2023-03-19 08:22:28 +01:00
|
|
|
import { IsNull } from "typeorm";
|
|
|
|
import { Emojis } from "@/models/index.js";
|
|
|
|
import define from "../define.js";
|
2023-07-21 22:15:53 +02:00
|
|
|
import { ApiError } from "../error.js";
|
2023-03-19 08:22:28 +01:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ["meta"],
|
|
|
|
|
|
|
|
requireCredential: false,
|
|
|
|
allowGet: true,
|
|
|
|
cacheSec: 3600,
|
|
|
|
|
2023-07-21 22:15:53 +02:00
|
|
|
errors: {
|
|
|
|
noSuchEmoji: {
|
|
|
|
message: "No such emoji.",
|
|
|
|
code: "NO_SUCH_EMOJI",
|
|
|
|
id: "6a5e3be7-5ac3-44a6-a425-9937cd66f8e1",
|
|
|
|
httpStatusCode: 404,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2023-03-19 08:22:28 +01:00
|
|
|
res: {
|
|
|
|
type: "object",
|
2023-03-31 04:10:03 +02:00
|
|
|
optional: false,
|
|
|
|
nullable: false,
|
2023-03-19 08:22:28 +01:00
|
|
|
ref: "Emoji",
|
|
|
|
},
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
export const paramDef = {
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
name: {
|
|
|
|
type: "string",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
required: ["name"],
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
export default define(meta, paramDef, async (ps, me) => {
|
2023-07-21 22:15:53 +02:00
|
|
|
const emoji = await Emojis.findOne({
|
2023-03-19 08:22:28 +01:00
|
|
|
where: {
|
|
|
|
name: ps.name,
|
|
|
|
host: IsNull(),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-07-21 22:15:53 +02:00
|
|
|
if (!emoji) {
|
|
|
|
throw new ApiError(meta.errors.noSuchEmoji);
|
|
|
|
}
|
|
|
|
|
2023-03-19 08:22:28 +01:00
|
|
|
return Emojis.pack(emoji);
|
|
|
|
});
|