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, { 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;
}); });
}); });

View file

@ -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();

View file

@ -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