feat: アバターデコレーションのファイルをユーザー依存にしない

This commit is contained in:
mai 2024-06-14 15:20:10 +00:00 committed by hijiki
parent 3f4fe38ecf
commit 7dde41d3b3
2 changed files with 23 additions and 2 deletions

View File

@ -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<typeof meta, typeof paramDef> { // 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);
});

View File

@ -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<typeof meta, typeof paramDef> { // 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);
});