mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-11-22 05:55:12 +00:00
fix: revert previous change and filter in the note processing instead
This commit is contained in:
parent
182ddd2c49
commit
4b24cce2c5
2 changed files with 23 additions and 19 deletions
|
@ -48,21 +48,20 @@ 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 (imageUrl == null) {
|
if (image.url == null) {
|
||||||
throw new Error('invalid image: url not provided');
|
throw new Error('invalid image: url not provided');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof imageUrl !== 'string') {
|
if (typeof image.url !== 'string') {
|
||||||
throw new Error('invalid image: unexpected type of url: ' + JSON.stringify(imageUrl, null, 2));
|
throw new Error('invalid image: unexpected type of url: ' + JSON.stringify(image.url, null, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!checkHttps(imageUrl)) {
|
if (!checkHttps(image.url)) {
|
||||||
throw new Error('invalid image: unexpected schema of url: ' + imageUrl);
|
throw new Error('invalid image: unexpected schema of url: ' + image.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.info(`Creating the Image: ${imageUrl}`);
|
this.logger.info(`Creating the Image: ${image.url}`);
|
||||||
|
|
||||||
const instance = await this.metaService.fetch();
|
const instance = await this.metaService.fetch();
|
||||||
|
|
||||||
|
@ -78,17 +77,17 @@ export class ApImageService {
|
||||||
});
|
});
|
||||||
|
|
||||||
const file = await this.driveService.uploadFromUrl({
|
const file = await this.driveService.uploadFromUrl({
|
||||||
url: imageUrl,
|
url: image.url,
|
||||||
user: actor,
|
user: actor,
|
||||||
uri: imageUrl,
|
uri: image.url,
|
||||||
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 === imageUrl) return file;
|
if (!file.isLink || file.url === image.url) return file;
|
||||||
|
|
||||||
// URLが異なっている場合、同じ画像が以前に異なるURLで登録されていたということなので、URLを更新する
|
// URLが異なっている場合、同じ画像が以前に異なるURLで登録されていたということなので、URLを更新する
|
||||||
await this.driveFilesRepository.update({ id: file.id }, { url: imageUrl, uri: imageUrl });
|
await this.driveFilesRepository.update({ id: file.id }, { url: image.url, uri: image.url });
|
||||||
return await this.driveFilesRepository.findOneByOrFail({ id: file.id });
|
return await this.driveFilesRepository.findOneByOrFail({ id: file.id });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -441,15 +441,20 @@ export class ApNoteService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添付ファイル
|
// 添付ファイル
|
||||||
// TODO: attachmentは必ずしもImageではない
|
const attachments = toArray(note.attachment);
|
||||||
// TODO: attachmentは必ずしも配列ではない
|
if (note.image)
|
||||||
|
attachments.push(note.image);
|
||||||
|
|
||||||
const limit = promiseLimit<MiDriveFile>(2);
|
const limit = promiseLimit<MiDriveFile>(2);
|
||||||
const files = (await Promise.all(toArray(note.attachment).map(attach => (
|
const filePromises = attachments
|
||||||
limit(() => this.apImageService.resolveImage(actor, {
|
.filter(attach => toArray(attach.type)?.includes('Image'))
|
||||||
...attach,
|
.map(attach => (
|
||||||
sensitive: note.sensitive, // Noteがsensitiveなら添付もsensitiveにする
|
limit(() => this.apImageService.resolveImage(actor, {
|
||||||
}))
|
...attach,
|
||||||
))));
|
sensitive: note.sensitive, // Noteがsensitiveなら添付もsensitiveにする
|
||||||
|
}))
|
||||||
|
));
|
||||||
|
const files = await Promise.all(filePromises);
|
||||||
|
|
||||||
// リプライ
|
// リプライ
|
||||||
const reply: MiNote | null = note.inReplyTo
|
const reply: MiNote | null = note.inReplyTo
|
||||||
|
|
Loading…
Reference in a new issue