This commit is contained in:
syuilo 2024-03-18 16:33:58 +09:00
parent fafef696bf
commit 250266ab73
3 changed files with 18 additions and 11 deletions

View file

@ -10,7 +10,6 @@ import { DI } from '@/di-symbols.js';
import { IdService } from '@/core/IdService.js'; import { IdService } from '@/core/IdService.js';
import { EmojiEntityService } from '@/core/entities/EmojiEntityService.js'; import { EmojiEntityService } from '@/core/entities/EmojiEntityService.js';
import { GlobalEventService } from '@/core/GlobalEventService.js'; import { GlobalEventService } from '@/core/GlobalEventService.js';
import type { MiDriveFile } from '@/models/DriveFile.js';
import type { MiEmoji } from '@/models/Emoji.js'; import type { MiEmoji } from '@/models/Emoji.js';
import type { EmojisRepository, MiRole, MiUser } from '@/models/_.js'; import type { EmojisRepository, MiRole, MiUser } from '@/models/_.js';
import { bindThis } from '@/decorators.js'; import { bindThis } from '@/decorators.js';
@ -104,7 +103,9 @@ export class CustomEmojiService implements OnApplicationShutdown {
@bindThis @bindThis
public async add(data: { public async add(data: {
driveFile: MiDriveFile; originalUrl: string;
publicUrl: string;
fileType: string;
name: string; name: string;
category: string | null; category: string | null;
aliases: string[]; aliases: string[];
@ -121,9 +122,9 @@ export class CustomEmojiService implements OnApplicationShutdown {
category: data.category, category: data.category,
host: data.host, host: data.host,
aliases: data.aliases, aliases: data.aliases,
originalUrl: data.driveFile.url, originalUrl: data.originalUrl,
publicUrl: data.driveFile.webpublicUrl ?? data.driveFile.url, publicUrl: data.publicUrl,
type: data.driveFile.webpublicType ?? data.driveFile.type, type: data.fileType,
license: data.license, license: data.license,
isSensitive: data.isSensitive, isSensitive: data.isSensitive,
localOnly: data.localOnly, localOnly: data.localOnly,
@ -150,7 +151,9 @@ export class CustomEmojiService implements OnApplicationShutdown {
@bindThis @bindThis
public async update(id: MiEmoji['id'], data: { public async update(id: MiEmoji['id'], data: {
driveFile?: MiDriveFile; originalUrl?: string;
publicUrl?: string;
fileType?: string;
name?: string; name?: string;
category?: string | null; category?: string | null;
aliases?: string[]; aliases?: string[];
@ -171,9 +174,9 @@ export class CustomEmojiService implements OnApplicationShutdown {
license: data.license, license: data.license,
isSensitive: data.isSensitive, isSensitive: data.isSensitive,
localOnly: data.localOnly, localOnly: data.localOnly,
originalUrl: data.driveFile != null ? data.driveFile.url : undefined, originalUrl: data.originalUrl,
publicUrl: data.driveFile != null ? (data.driveFile.webpublicUrl ?? data.driveFile.url) : undefined, publicUrl: data.publicUrl,
type: data.driveFile != null ? (data.driveFile.webpublicType ?? data.driveFile.type) : undefined, type: data.fileType,
roleIdsThatCanBeUsedThisEmojiAsReaction: data.roleIdsThatCanBeUsedThisEmojiAsReaction ?? undefined, roleIdsThatCanBeUsedThisEmojiAsReaction: data.roleIdsThatCanBeUsedThisEmojiAsReaction ?? undefined,
}); });

View file

@ -90,7 +90,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (!FILE_TYPE_IMAGE.includes(driveFile.type)) throw new ApiError(meta.errors.notSupportFileType); if (!FILE_TYPE_IMAGE.includes(driveFile.type)) throw new ApiError(meta.errors.notSupportFileType);
const emoji = await this.customEmojiService.add({ const emoji = await this.customEmojiService.add({
driveFile, originalUrl: driveFile.url,
publicUrl: driveFile.webpublicUrl ?? driveFile.url,
fileType: driveFile.webpublicType ?? driveFile.type,
name: ps.name, name: ps.name,
category: ps.category ?? null, category: ps.category ?? null,
aliases: ps.aliases ?? [], aliases: ps.aliases ?? [],

View file

@ -95,7 +95,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
} }
await this.customEmojiService.update(emojiId, { await this.customEmojiService.update(emojiId, {
driveFile, originalUrl: driveFile != null ? driveFile.url : undefined,
publicUrl: driveFile != null ? (driveFile.webpublicUrl ?? driveFile.url) : undefined,
fileType: driveFile != null ? (driveFile.webpublicType ?? driveFile.type) : undefined,
name: ps.name, name: ps.name,
category: ps.category, category: ps.category,
aliases: ps.aliases, aliases: ps.aliases,