From 67f9d9db4cf298dc26584c521755d295f938567e Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 05:41:51 +0900 Subject: [PATCH] =?UTF-8?q?refactor(`ApImageService.ts`):=20=E5=86=97?= =?UTF-8?q?=E9=95=B7=E3=81=A0=E3=81=A3=E3=81=9F=E9=83=A8=E5=88=86=E3=82=92?= =?UTF-8?q?=E7=9F=AD=E3=81=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/activitypub/models/ApImageService.ts | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApImageService.ts b/packages/backend/src/core/activitypub/models/ApImageService.ts index f7b716a411..0476e845ed 100644 --- a/packages/backend/src/core/activitypub/models/ApImageService.ts +++ b/packages/backend/src/core/activitypub/models/ApImageService.ts @@ -62,7 +62,7 @@ export class ApImageService { const instance = await this.metaService.fetch(); - let file = await this.driveService.uploadFromUrl({ + const file = await this.driveService.uploadFromUrl({ url: image.url, user: actor, uri: image.url, @@ -70,21 +70,11 @@ export class ApImageService { isLink: !instance.cacheRemoteFiles, comment: truncate(image.name ?? undefined, DB_MAX_IMAGE_COMMENT_LENGTH), }); + if (!file.isLink || file.url === image.url) return file; - if (file.isLink) { - // URLが異なっている場合、同じ画像が以前に異なるURLで登録されていたということなので、 - // URLを更新する - if (file.url !== image.url) { - await this.driveFilesRepository.update({ id: file.id }, { - url: image.url, - uri: image.url, - }); - - file = await this.driveFilesRepository.findOneByOrFail({ id: file.id }); - } - } - - return file; + // URLが異なっている場合、同じ画像が以前に異なるURLで登録されていたということなので、URLを更新する + await this.driveFilesRepository.update({ id: file.id }, { url: image.url, uri: image.url }); + return await this.driveFilesRepository.findOneByOrFail({ id: file.id }); } /**