diff --git a/packages/backend/src/core/activitypub/models/ApImageService.ts b/packages/backend/src/core/activitypub/models/ApImageService.ts index 1017a5018a..5f381108a3 100644 --- a/packages/backend/src/core/activitypub/models/ApImageService.ts +++ b/packages/backend/src/core/activitypub/models/ApImageService.ts @@ -48,20 +48,21 @@ export class ApImageService { } const image = await this.apResolverService.createResolver().resolve(value); + const imageUrl = image.url ?? image.href; - if (image.url == null) { + if (imageUrl == null) { throw new Error('invalid image: url not provided'); } - if (typeof image.url !== 'string') { - throw new Error('invalid image: unexpected type of url: ' + JSON.stringify(image.url, null, 2)); + if (typeof imageUrl !== 'string') { + throw new Error('invalid image: unexpected type of url: ' + JSON.stringify(imageUrl, null, 2)); } - if (!checkHttps(image.url)) { - throw new Error('invalid image: unexpected schema of url: ' + image.url); + if (!checkHttps(imageUrl)) { + throw new Error('invalid image: unexpected schema of url: ' + imageUrl); } - this.logger.info(`Creating the Image: ${image.url}`); + this.logger.info(`Creating the Image: ${imageUrl}`); const instance = await this.metaService.fetch(); @@ -77,17 +78,17 @@ export class ApImageService { }); const file = await this.driveService.uploadFromUrl({ - url: image.url, + url: imageUrl, user: actor, - uri: image.url, + uri: imageUrl, sensitive: image.sensitive, isLink: !shouldBeCached, comment: truncate(image.name ?? undefined, DB_MAX_IMAGE_COMMENT_LENGTH), }); - if (!file.isLink || file.url === image.url) return file; + if (!file.isLink || file.url === imageUrl) return file; // URLが異なっている場合、同じ画像が以前に異なるURLで登録されていたということなので、URLを更新する - await this.driveFilesRepository.update({ id: file.id }, { url: image.url, uri: image.url }); + await this.driveFilesRepository.update({ id: file.id }, { url: imageUrl, uri: imageUrl }); return await this.driveFilesRepository.findOneByOrFail({ id: file.id }); }