From 7dde41d3b35cd57a0ce2882f34dc2bb40a7e6952 Mon Sep 17 00:00:00 2001 From: mai <74494945+chan-mai@users.noreply.github.com> Date: Fri, 14 Jun 2024 15:20:10 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=82=A2=E3=83=90=E3=82=BF=E3=83=BC?= =?UTF-8?q?=E3=83=87=E3=82=B3=E3=83=AC=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=81=AE=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E3=83=A6?= =?UTF-8?q?=E3=83=BC=E3=82=B6=E3=83=BC=E4=BE=9D=E5=AD=98=E3=81=AB=E3=81=97?= =?UTF-8?q?=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../endpoints/admin/avatar-decorations/create.ts | 10 +++++++++- .../endpoints/admin/avatar-decorations/update.ts | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) 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 fd21309818..5e52d8e2b5 100755 --- 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 34b3b5a11f..9f12901d94 100755 --- 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); });