Hide private data in pug when private mode is enabled

This commit is contained in:
nullobsi 2021-08-25 20:48:57 -07:00 committed by Kayden Tebau
parent a69557f193
commit 3f14e23431
No known key found for this signature in database
GPG key ID: 933A1F44222C2634
8 changed files with 135 additions and 101 deletions

View file

@ -218,6 +218,10 @@ router.get('/api.json', async ctx => {
});
const getFeed = async (acct: string) => {
const meta = await fetchMeta();
if (meta.privateMode) {
return;
}
const { username, host } = Acct.parse(acct);
const user = await Users.findOneBy({
usernameLower: username.toLowerCase(),
@ -290,6 +294,7 @@ router.get(['/@:user', '/@:user/:sub'], async (ctx, next) => {
instanceName: meta.name || 'Misskey',
icon: meta.iconUrl,
themeColor: meta.themeColor,
privateMode: meta.privateMode,
});
ctx.set('Cache-Control', 'public, max-age=15');
} else {
@ -333,6 +338,7 @@ router.get('/notes/:note', async (ctx, next) => {
summary: getNoteSummary(_note),
instanceName: meta.name || 'Misskey',
icon: meta.iconUrl,
privateMode: meta.privateMode,
themeColor: meta.themeColor,
});
@ -370,6 +376,7 @@ router.get('/@:user/pages/:page', async (ctx, next) => {
instanceName: meta.name || 'Misskey',
icon: meta.iconUrl,
themeColor: meta.themeColor,
privateMode: meta.privateMode,
});
if (['public'].includes(page.visibility)) {
@ -400,6 +407,7 @@ router.get('/clips/:clip', async (ctx, next) => {
profile,
avatarUrl: await Users.getAvatarUrl(await Users.findOneByOrFail({ id: clip.userId })),
instanceName: meta.name || 'Misskey',
privateMode: meta.privateMode,
icon: meta.iconUrl,
themeColor: meta.themeColor,
});
@ -427,6 +435,7 @@ router.get('/gallery/:post', async (ctx, next) => {
instanceName: meta.name || 'Misskey',
icon: meta.iconUrl,
themeColor: meta.themeColor,
privateMode: meta.privateMode,
});
ctx.set('Cache-Control', 'public, max-age=15');
@ -451,6 +460,7 @@ router.get('/channels/:channel', async (ctx, next) => {
instanceName: meta.name || 'Misskey',
icon: meta.iconUrl,
themeColor: meta.themeColor,
privateMode: meta.privateMode,
});
ctx.set('Cache-Control', 'public, max-age=15');
@ -464,6 +474,10 @@ router.get('/channels/:channel', async (ctx, next) => {
router.get('/_info_card_', async ctx => {
const meta = await fetchMeta(true);
if (meta.privateMode) {
ctx.status = 403;
return;
}
ctx.remove('X-Frame-Options');
@ -511,6 +525,7 @@ router.get('(.*)', async ctx => {
desc: meta.description,
icon: meta.iconUrl,
themeColor: meta.themeColor,
privateMode: meta.privateMode,
});
ctx.set('Cache-Control', 'public, max-age=15');
});

View file

@ -51,6 +51,8 @@ html
meta(name='description' content= desc || '✨🌎✨ A interplanetary communication platform ✨🚀✨')
block meta
if privateMode
meta(name='robots' content='noindex')
block og
meta(property='og:title' content= title || 'Misskey')

View file

@ -1,16 +1,18 @@
extends ./base
block vars
- const title = channel.name;
- const title = privateMode ? '非公開インスタンス' : channel.name;
- const url = `${config.url}/channels/${channel.id}`;
block title
= `${title} | ${instanceName}`
block desc
meta(name='description' content= channel.description)
unless privateMode
meta(name='description' content=channel.description)
block og
unless privateMode
meta(property='og:type' content='article')
meta(property='og:title' content= title)
meta(property='og:description' content= channel.description)

View file

@ -2,16 +2,18 @@ extends ./base
block vars
- const user = clip.user;
- const title = clip.name;
- const title = privateMode ? '非公開インスタンス' : clip.name;
- const url = `${config.url}/clips/${clip.id}`;
block title
= `${title} | ${instanceName}`
block desc
unless privateMode
meta(name='description' content= clip.description)
block og
unless privateMode
meta(property='og:type' content='article')
meta(property='og:title' content= title)
meta(property='og:description' content= clip.description)
@ -19,6 +21,7 @@ block og
meta(property='og:image' content= avatarUrl)
block meta
unless privateMode
if profile.noCrawle
meta(name='robots' content='noindex')

View file

@ -2,16 +2,18 @@ extends ./base
block vars
- const user = post.user;
- const title = post.title;
- const title = privateMode ? '非公開インスタンス' : post.title;
- const url = `${config.url}/gallery/${post.id}`;
block title
= `${title} | ${instanceName}`
block desc
unless privateMode
meta(name='description' content= post.description)
block og
unless privateMode
meta(property='og:type' content='article')
meta(property='og:title' content= title)
meta(property='og:description' content= post.description)
@ -19,6 +21,7 @@ block og
meta(property='og:image' content= post.files[0].thumbnailUrl)
block meta
unless privateMode
if user.host || profile.noCrawle
meta(name='robots' content='noindex')

View file

@ -2,7 +2,7 @@ extends ./base
block vars
- const user = note.user;
- const title = user.name ? `${user.name} (@${user.username})` : `@${user.username}`;
- const title = privateMode ? '非公開インスタンス' : (user.name ? `${user.name} (@${user.username})` : `@${user.username}`);
- const url = `${config.url}/notes/${note.id}`;
- const isRenote = note.renote && note.text == null && note.fileIds.length == 0 && note.poll == null;
@ -10,9 +10,11 @@ block title
= `${title} | ${instanceName}`
block desc
unless privateMode
meta(name='description' content= summary)
block og
unless privateMode
meta(property='og:type' content='article')
meta(property='og:title' content= title)
meta(property='og:description' content= summary)
@ -20,6 +22,7 @@ block og
meta(property='og:image' content= avatarUrl)
block meta
unless privateMode
if user.host || isRenote || profile.noCrawle
meta(name='robots' content='noindex')

View file

@ -2,16 +2,18 @@ extends ./base
block vars
- const user = page.user;
- const title = page.title;
- const title = privateMode ? '非公開インスタンス' : page.title;
- const url = `${config.url}/@${user.username}/${page.name}`;
block title
= `${title} | ${instanceName}`
block desc
unless privateMode
meta(name='description' content= page.summary)
block og
unless privateMode
meta(property='og:type' content='article')
meta(property='og:title' content= title)
meta(property='og:description' content= page.summary)
@ -19,6 +21,7 @@ block og
meta(property='og:image' content= page.eyeCatchingImage ? page.eyeCatchingImage.thumbnailUrl : avatarUrl)
block meta
unless privateMode
if profile.noCrawle
meta(name='robots' content='noindex')

View file

@ -1,16 +1,18 @@
extends ./base
block vars
- const title = user.name ? `${user.name} (@${user.username})` : `@${user.username}`;
- const title = privateMode ? '非公開インスタンス' : (user.name ? `${user.name} (@${user.username})` : `@${user.username}`);
- const url = `${config.url}/@${(user.host ? `${user.username}@${user.host}` : user.username)}`;
block title
= `${title} | ${instanceName}`
block desc
unless privateMode
meta(name='description' content= profile.description)
block og
unless privateMode
meta(property='og:type' content='blog')
meta(property='og:title' content= title)
meta(property='og:description' content= profile.description)
@ -18,6 +20,7 @@ block og
meta(property='og:image' content= avatarUrl)
block meta
unless privateMode
if user.host || profile.noCrawle
meta(name='robots' content='noindex')