diff --git a/packages/backend/src/server/api/endpoints/admin/avatar-decorations/create.ts b/packages/backend/src/server/api/endpoints/admin/avatar-decorations/create.ts index fd213098188d..5e52d8e2b52a 100644 --- a/packages/backend/src/server/api/endpoints/admin/avatar-decorations/create.ts +++ b/packages/backend/src/server/api/endpoints/admin/avatar-decorations/create.ts @@ -6,6 +6,7 @@ import { Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { AvatarDecorationService } from '@/core/AvatarDecorationService.js'; +import { DriveService } from '@/core/DriveService.js'; export const meta = { tags: ['admin'], @@ -32,12 +33,19 @@ export const paramDef = { export default class extends Endpoint { // eslint-disable-line import/no-default-export constructor( private avatarDecorationService: AvatarDecorationService, + private driveService: DriveService, ) { super(meta, paramDef, async (ps, me) => { + // システムユーザーとして再アップロード + const sysFileData = await this.driveService.uploadFromUrl({ + url: ps.url, + user: null, + force: true, + }); await this.avatarDecorationService.create({ name: ps.name, description: ps.description, - url: ps.url, + url: sysFileData.url, roleIdsThatCanBeUsedThisDecoration: ps.roleIdsThatCanBeUsedThisDecoration, }, me); }); diff --git a/packages/backend/src/server/api/endpoints/admin/avatar-decorations/update.ts b/packages/backend/src/server/api/endpoints/admin/avatar-decorations/update.ts index 34b3b5a11f50..9f12901d948a 100644 --- a/packages/backend/src/server/api/endpoints/admin/avatar-decorations/update.ts +++ b/packages/backend/src/server/api/endpoints/admin/avatar-decorations/update.ts @@ -7,6 +7,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { DI } from '@/di-symbols.js'; import { AvatarDecorationService } from '@/core/AvatarDecorationService.js'; +import { DriveService } from '@/core/DriveService.js'; import { ApiError } from '../../../error.js'; export const meta = { @@ -38,12 +39,24 @@ export const paramDef = { export default class extends Endpoint { // eslint-disable-line import/no-default-export constructor( private avatarDecorationService: AvatarDecorationService, + private driveService: DriveService, ) { super(meta, paramDef, async (ps, me) => { + let fileUrl = ps.url; + // URLに変更があるか + if (typeof ps.url !== 'undefined' || typeof ps.url === 'string' ) { + // システムユーザーとして再アップロード + const sysFileData = await this.driveService.uploadFromUrl({ + url: ps.url, + user: null, + force: true, + }); + fileUrl = sysFileData.url; + } await this.avatarDecorationService.update(ps.id, { name: ps.name, description: ps.description, - url: ps.url, + url: fileUrl, roleIdsThatCanBeUsedThisDecoration: ps.roleIdsThatCanBeUsedThisDecoration, }, me); });