fix: accept images with "href" instead of "url"
This commit is contained in:
parent
d0a2708f91
commit
182ddd2c49
|
@ -48,20 +48,21 @@ export class ApImageService {
|
||||||
}
|
}
|
||||||
|
|
||||||
const image = await this.apResolverService.createResolver().resolve(value);
|
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');
|
throw new Error('invalid image: url not provided');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof image.url !== 'string') {
|
if (typeof imageUrl !== 'string') {
|
||||||
throw new Error('invalid image: unexpected type of url: ' + JSON.stringify(image.url, null, 2));
|
throw new Error('invalid image: unexpected type of url: ' + JSON.stringify(imageUrl, null, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!checkHttps(image.url)) {
|
if (!checkHttps(imageUrl)) {
|
||||||
throw new Error('invalid image: unexpected schema of url: ' + image.url);
|
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();
|
const instance = await this.metaService.fetch();
|
||||||
|
|
||||||
|
@ -77,17 +78,17 @@ export class ApImageService {
|
||||||
});
|
});
|
||||||
|
|
||||||
const file = await this.driveService.uploadFromUrl({
|
const file = await this.driveService.uploadFromUrl({
|
||||||
url: image.url,
|
url: imageUrl,
|
||||||
user: actor,
|
user: actor,
|
||||||
uri: image.url,
|
uri: imageUrl,
|
||||||
sensitive: image.sensitive,
|
sensitive: image.sensitive,
|
||||||
isLink: !shouldBeCached,
|
isLink: !shouldBeCached,
|
||||||
comment: truncate(image.name ?? undefined, DB_MAX_IMAGE_COMMENT_LENGTH),
|
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を更新する
|
// 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 });
|
return await this.driveFilesRepository.findOneByOrFail({ id: file.id });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue