Skip to content

Commit

Permalink
feat: アバターデコレーションのファイルをユーザー依存にしない
Browse files Browse the repository at this point in the history
  • Loading branch information
chan-mai committed Jun 14, 2024
1 parent 217e35a commit 6daa8cc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);
});
Expand Down

0 comments on commit 6daa8cc

Please sign in to comment.