iceshrimp-legacy/packages/backend/src/server/api/endpoints/admin/emoji/update.ts
naskya 1c0d4546f7 feat: set license information for custom emojis (#9719)
Closes: #9711 (please check this issue first)

I cherry-picked two commits ([1](8ae9d2eaa8), [2](ed51209172)) from [Misskey](https://github.com/misskey-dev/misskey) and made a few changes.
「ライセンス」should be written as "License" in the following screenshots, but it has not yet been translated.

It would be nice if we could include multiple lines of text, but I just ported what's been implemented so far in Misskey not to mess things up.

This is my first pull request (aside from typo correction). Feel free to point out any issues!

![](https://cdn.discordapp.com/attachments/823878222897741868/1086372711841935440/2023-03-18_042011.png)
![](https://cdn.discordapp.com/attachments/823878222897741868/1086373178214981853/01.png)
![](https://cdn.discordapp.com/attachments/823878222897741868/1086373336709341246/2023-03-18_042629.png)

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
Co-authored-by: naskya <m@naskya.net>
Reviewed-on: https://codeberg.org/calckey/calckey/pulls/9719
Co-authored-by: naskya <naskya@noreply.codeberg.org>
Co-committed-by: naskya <naskya@noreply.codeberg.org>
2023-03-19 07:22:28 +00:00

60 lines
1.2 KiB
TypeScript

import define from "../../../define.js";
import { Emojis } from "@/models/index.js";
import { ApiError } from "../../../error.js";
import { db } from "@/db/postgre.js";
export const meta = {
tags: ["admin"],
requireCredential: true,
requireModerator: true,
errors: {
noSuchEmoji: {
message: "No such emoji.",
code: "NO_SUCH_EMOJI",
id: "684dec9d-a8c2-4364-9aa8-456c49cb1dc8",
},
},
} as const;
export const paramDef = {
type: "object",
properties: {
id: { type: "string", format: "misskey:id" },
name: { type: "string" },
category: {
type: "string",
nullable: true,
description: "Use `null` to reset the category.",
},
aliases: {
type: "array",
items: {
type: "string",
},
},
license: {
type: "string",
nullable: true,
},
},
required: ["id", "name", "aliases"],
} as const;
export default define(meta, paramDef, async (ps) => {
const emoji = await Emojis.findOneBy({ id: ps.id });
if (emoji == null) throw new ApiError(meta.errors.noSuchEmoji);
await Emojis.update(emoji.id, {
updatedAt: new Date(),
name: ps.name,
category: ps.category,
aliases: ps.aliases,
license: ps.license,
});
await db.queryResultCache!.remove(["meta_emojis"]);
});