fix: catch errors from packing with detail

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:
Johann150 2022-06-10 08:06:02 +02:00
parent b630cd7eac
commit 3fe351df6d
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
3 changed files with 44 additions and 25 deletions

View file

@ -39,6 +39,10 @@ export default define(meta, paramDef, async (ps, 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,
}).catch(err => {
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
throw err;
});
});

View file

@ -322,23 +322,32 @@ router.get('/notes/:note', async (ctx, next) => {
});
if (note) {
const _note = await Notes.pack(note);
const profile = await UserProfiles.findOneByOrFail({ userId: note.userId });
const meta = await fetchMeta();
await ctx.render('note', {
note: _note,
profile,
avatarUrl: await Users.getAvatarUrl(await Users.findOneByOrFail({ id: note.userId })),
// TODO: Let locale changeable by instance setting
summary: getNoteSummary(_note),
instanceName: meta.name || 'Misskey',
icon: meta.iconUrl,
themeColor: meta.themeColor,
});
try {
// FIXME: packing with detail may throw an error if the reply or renote is not visible (#8774)
const _note = await Notes.pack(note);
const profile = await UserProfiles.findOneByOrFail({ userId: note.userId });
const meta = await fetchMeta();
await ctx.render('note', {
note: _note,
profile,
avatarUrl: await Users.getAvatarUrl(await Users.findOneByOrFail({ id: note.userId })),
// TODO: Let locale changeable by instance setting
summary: getNoteSummary(_note),
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();

View file

@ -640,17 +640,23 @@ async function createMentionedEvents(mentionedUsers: MinimumUser[], note: Note,
continue;
}
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,
// note with "specified" visibility might not be visible to mentioned users
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,
});
}
} catch (err) {
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') continue;
throw err;
}
// Create notification