Skip to content

Commit

Permalink
fix: 再アップロード後に消去する処理を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
chan-mai committed Jul 9, 2024
1 parent e7a9c92 commit bad42bb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/backend/src/core/CustomEmojiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,18 @@ export class CustomEmojiService implements OnApplicationShutdown {
localOnly: boolean;
roleIdsThatCanBeUsedThisEmojiAsReaction: MiRole['id'][];
}, moderator?: MiUser): Promise<MiEmoji> {
const originalDriveData: MiDriveFile = data.driveFile;

// システムユーザーとして再アップロード
if (!data.driveFile.user?.isRoot) {
data.driveFile = await this.driveService.uploadFromUrl({
url: data.driveFile.url,
user: null,
force: true,
});

// 元データの削除
this.driveService.deleteFile(originalDriveData);
}
const emoji = await this.emojisRepository.insertOne({
id: this.idService.gen(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private avatarDecorationService: AvatarDecorationService,
private driveService: DriveService,
) {
super(meta, paramDef, async (ps, me) => {
super(meta, paramDef, async (ps: any, me) => {
// システムユーザーとして再アップロード
const sysFileData = await this.driveService.uploadFromUrl({
url: ps.url,
user: null,
force: true,
});

// 元ファイルの削除
this.driveService.deleteFile(ps);

await this.avatarDecorationService.create({
name: ps.name,
description: ps.description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private avatarDecorationService: AvatarDecorationService,
private driveService: DriveService,
) {
super(meta, paramDef, async (ps, me) => {
super(meta, paramDef, async (ps: any, me) => {
let fileUrl = ps.url;
// URLに変更があるか
if (typeof ps.url !== 'undefined' || typeof ps.url === 'string' ) {
Expand All @@ -52,6 +52,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
force: true,
});
fileUrl = sysFileData.url;

// 元ファイルの削除
this.driveService.deleteFile(ps);
}
await this.avatarDecorationService.update(ps.id, {
name: ps.name,
Expand Down

0 comments on commit bad42bb

Please sign in to comment.