diff options
| author | Kagami Sascha Rosylight <saschanaz@outlook.com> | 2023-08-08 06:26:03 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-08 13:26:03 +0900 |
| commit | ec229dbd3b50fdb644dd9e6903e0544be21e55f1 (patch) | |
| tree | ccd51a5ab2ad843722357e3a0f142bba48054139 /packages/backend/src/core | |
| parent | enhance(backend): Improve behavior of correctFilename (#11484) (diff) | |
| download | misskey-ec229dbd3b50fdb644dd9e6903e0544be21e55f1.tar.gz misskey-ec229dbd3b50fdb644dd9e6903e0544be21e55f1.tar.bz2 misskey-ec229dbd3b50fdb644dd9e6903e0544be21e55f1.zip | |
fix(backend/ApNoteService): try retrieving again when failed by duplication (#11472)
* fix(backend/ApNoteService): try retrieving again when failed by duplication
* Update CHANGELOG.md
---------
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
Diffstat (limited to 'packages/backend/src/core')
| -rw-r--r-- | packages/backend/src/core/activitypub/models/ApNoteService.ts | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index e107b9fe5a..41d1bc48a7 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -131,13 +131,13 @@ export class ApNoteService { this.logger.debug(`Note fetched: ${JSON.stringify(note, null, 2)}`); if (note.id && !checkHttps(note.id)) { - throw new Error('unexpected shcema of note.id: ' + note.id); + throw new Error('unexpected schema of note.id: ' + note.id); } const url = getOneApHrefNullable(note.url); if (url && !checkHttps(url)) { - throw new Error('unexpected shcema of note url: ' + url); + throw new Error('unexpected schema of note url: ' + url); } this.logger.info(`Creating the Note: ${note.id}`); @@ -271,24 +271,36 @@ export class ApNoteService { const poll = await this.apQuestionService.extractPollFromQuestion(note, resolver).catch(() => undefined); - return await this.noteCreateService.create(actor, { - createdAt: note.published ? new Date(note.published) : null, - files, - reply, - renote: quote, - name: note.name, - cw, - text, - localOnly: false, - visibility, - visibleUsers, - apMentions, - apHashtags, - apEmojis, - poll, - uri: note.id, - url: url, - }, silent); + try { + return await this.noteCreateService.create(actor, { + createdAt: note.published ? new Date(note.published) : null, + files, + reply, + renote: quote, + name: note.name, + cw, + text, + localOnly: false, + visibility, + visibleUsers, + apMentions, + apHashtags, + apEmojis, + poll, + uri: note.id, + url: url, + }, silent); + } catch (err: any) { + if (err.name !== 'duplicated') { + throw err; + } + this.logger.info('The note is already inserted while creating itself, reading again'); + const duplicate = await this.fetchNote(value); + if (!duplicate) { + throw new Error('The note creation failed with duplication error even when there is no duplication'); + } + return duplicate; + } } /** |