fix: catch errors from packing with detail
Some checks failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-backend Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/lint-backend Pipeline was successful
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/test Pipeline failed
ci/woodpecker/pr/lint-client Pipeline failed
ci/woodpecker/pr/test Pipeline failed
Some checks failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-backend Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/lint-backend Pipeline was successful
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/test Pipeline failed
ci/woodpecker/pr/lint-client Pipeline failed
ci/woodpecker/pr/test Pipeline failed
Packing with detail can cause an error if the reply or renote are not visible to the user, even though the original note is visible to the user.
This commit is contained in:
parent
b630cd7eac
commit
3fe351df6d
3 changed files with 44 additions and 25 deletions
|
@ -39,6 +39,10 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
return await Notes.pack(note, user, {
|
return await Notes.pack(note, user, {
|
||||||
|
// FIXME: packing with detail may throw an error if the reply or renote is not visible (#8774)
|
||||||
detail: true,
|
detail: true,
|
||||||
|
}).catch(err => {
|
||||||
|
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||||
|
throw err;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -322,23 +322,32 @@ router.get('/notes/:note', async (ctx, next) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (note) {
|
if (note) {
|
||||||
const _note = await Notes.pack(note);
|
try {
|
||||||
const profile = await UserProfiles.findOneByOrFail({ userId: note.userId });
|
// FIXME: packing with detail may throw an error if the reply or renote is not visible (#8774)
|
||||||
const meta = await fetchMeta();
|
const _note = await Notes.pack(note);
|
||||||
await ctx.render('note', {
|
const profile = await UserProfiles.findOneByOrFail({ userId: note.userId });
|
||||||
note: _note,
|
const meta = await fetchMeta();
|
||||||
profile,
|
await ctx.render('note', {
|
||||||
avatarUrl: await Users.getAvatarUrl(await Users.findOneByOrFail({ id: note.userId })),
|
note: _note,
|
||||||
// TODO: Let locale changeable by instance setting
|
profile,
|
||||||
summary: getNoteSummary(_note),
|
avatarUrl: await Users.getAvatarUrl(await Users.findOneByOrFail({ id: note.userId })),
|
||||||
instanceName: meta.name || 'Misskey',
|
// TODO: Let locale changeable by instance setting
|
||||||
icon: meta.iconUrl,
|
summary: getNoteSummary(_note),
|
||||||
themeColor: meta.themeColor,
|
instanceName: meta.name || 'Misskey',
|
||||||
});
|
icon: meta.iconUrl,
|
||||||
|
themeColor: meta.themeColor,
|
||||||
|
});
|
||||||
|
|
||||||
ctx.set('Cache-Control', 'public, max-age=15');
|
ctx.set('Cache-Control', 'public, max-age=15');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
} catch (err) {
|
||||||
|
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') {
|
||||||
|
// note not visible to user
|
||||||
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await next();
|
await next();
|
||||||
|
|
|
@ -640,17 +640,23 @@ async function createMentionedEvents(mentionedUsers: MinimumUser[], note: Note,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const detailPackedNote = await Notes.pack(note, u, {
|
// note with "specified" visibility might not be visible to mentioned users
|
||||||
detail: true,
|
try {
|
||||||
});
|
const detailPackedNote = await Notes.pack(note, u, {
|
||||||
|
detail: true,
|
||||||
publishMainStream(u.id, 'mention', detailPackedNote);
|
|
||||||
|
|
||||||
const webhooks = (await getActiveWebhooks()).filter(x => x.userId === u.id && x.on.includes('mention'));
|
|
||||||
for (const webhook of webhooks) {
|
|
||||||
webhookDeliver(webhook, 'mention', {
|
|
||||||
note: detailPackedNote,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
publishMainStream(u.id, 'mention', detailPackedNote);
|
||||||
|
|
||||||
|
const webhooks = (await getActiveWebhooks()).filter(x => x.userId === u.id && x.on.includes('mention'));
|
||||||
|
for (const webhook of webhooks) {
|
||||||
|
webhookDeliver(webhook, 'mention', {
|
||||||
|
note: detailPackedNote,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') continue;
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create notification
|
// Create notification
|
||||||
|
|
Loading…
Reference in a new issue