ローカルのカスタム絵文字については直接オリジナルURLにリクエストするように

This commit is contained in:
syuilo
2023-01-21 20:40:09 +09:00
parent bd469420fa
commit 3e112da486
5 changed files with 21 additions and 5 deletions

View File

@@ -22,7 +22,7 @@ export class EmojiEntityService {
@bindThis
public async pack(
src: Emoji['id'] | Emoji,
opts: { omitHost?: boolean; omitId?: boolean; } = {},
opts: { omitHost?: boolean; omitId?: boolean; withUrl?: boolean; } = {},
): Promise<Packed<'Emoji'>> {
const emoji = typeof src === 'object' ? src : await this.emojisRepository.findOneByOrFail({ id: src });
@@ -32,13 +32,15 @@ export class EmojiEntityService {
name: emoji.name,
category: emoji.category,
host: opts.omitHost ? undefined : emoji.host,
// ?? emoji.originalUrl してるのは後方互換性のため
url: opts.withUrl ? (emoji.publicUrl ?? emoji.originalUrl) : undefined,
};
}
@bindThis
public packMany(
emojis: any[],
opts: { omitHost?: boolean; omitId?: boolean; } = {},
opts: { omitHost?: boolean; omitId?: boolean; withUrl?: boolean; } = {},
) {
return Promise.all(emojis.map(x => this.pack(x, opts)));
}

View File

@@ -29,5 +29,9 @@ export const packedEmojiSchema = {
optional: true, nullable: true,
description: 'The local host is represented with `null`.',
},
url: {
type: 'string',
optional: true, nullable: false,
},
},
} as const;

View File

@@ -83,6 +83,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
emojis: await this.emojiEntityService.packMany(emojis, {
omitId: true,
omitHost: true,
withUrl: true,
}),
};
});