Skip rendering private data in privateMode
Some checks failed
ci/woodpecker/pr/lint-backend Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/lint-client Pipeline failed
ci/woodpecker/pr/test Pipeline failed

This reverts commit cfd251d9dc.

Instead of adding a conditional in the Pug templates, just skip
rendering altogether on the affected routes.

From #31:
> I'm not really happy with how the pug templates have
> unless privatemode everywhere. I think it would make more sense to
> not render the template in the first place if you are in private
> mode? I think you should be able to just skip to next in the
> router as if you didn't find something.
This commit is contained in:
Norm 2022-07-31 23:03:37 -04:00
parent cce01c9a70
commit e5595ca31c
Signed by: norm
GPG key ID: 7123E30E441E80DE
8 changed files with 135 additions and 125 deletions

View file

@ -22,11 +22,12 @@ import { Users, Notes, UserProfiles, Pages, Channels, Clips, GalleryPosts } from
import * as Acct from '@/misc/acct.js';
import { getNoteSummary } from '@/misc/get-note-summary.js';
import { queues } from '@/queue/queues.js';
import { MINUTE, DAY } from '@/const.js';
import { genOpenapiSpec } from '../api/openapi/gen-spec.js';
import meta from '../api/endpoints/meta.js';
import { urlPreviewHandler } from './url-preview.js';
import { manifestHandler } from './manifest.js';
import packFeed from './feed.js';
import { MINUTE, DAY } from '@/const.js';
const _filename = fileURLToPath(import.meta.url);
const _dirname = dirname(_filename);
@ -271,6 +272,12 @@ router.get('/@:user.json', async ctx => {
//#region SSR (for crawlers)
// User
router.get(['/@:user', '/@:user/:sub'], async (ctx, next) => {
const meta = await fetchMeta();
if (meta.privateMode) {
await next();
return;
}
const { username, host } = Acct.parse(ctx.params.user);
const user = await Users.findOneBy({
usernameLower: username.toLowerCase(),
@ -294,7 +301,6 @@ 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 {
@ -360,6 +366,12 @@ router.get('/notes/:note', async (ctx, next) => {
// Page
router.get('/@:user/pages/:page', async (ctx, next) => {
const meta = await fetchMeta();
if (meta.privateMode) {
await next();
return;
}
const { username, host } = Acct.parse(ctx.params.user);
const user = await Users.findOneBy({
usernameLower: username.toLowerCase(),
@ -384,7 +396,6 @@ 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)) {
@ -402,6 +413,12 @@ router.get('/@:user/pages/:page', async (ctx, next) => {
// Clip
// TODO: 非publicなclipのハンドリング
router.get('/clips/:clip', async (ctx, next) => {
const meta = await fetchMeta();
if (meta.privateMode) {
await next();
return;
}
const clip = await Clips.findOneBy({
id: ctx.params.clip,
});
@ -415,7 +432,6 @@ 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,
});
@ -430,6 +446,12 @@ router.get('/clips/:clip', async (ctx, next) => {
// Gallery post
router.get('/gallery/:post', async (ctx, next) => {
const meta = await fetchMeta();
if (meta.privateMode) {
await next();
return;
}
const post = await GalleryPosts.findOneBy({ id: ctx.params.post });
if (post) {
@ -443,7 +465,6 @@ 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');
@ -456,6 +477,12 @@ router.get('/gallery/:post', async (ctx, next) => {
// Channel
router.get('/channels/:channel', async (ctx, next) => {
const meta = await fetchMeta();
if (meta.privateMode) {
await next();
return;
}
const channel = await Channels.findOneBy({
id: ctx.params.channel,
});
@ -468,7 +495,6 @@ 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');
@ -526,6 +552,10 @@ router.get('/streaming', async ctx => {
// Render base html for all requests
router.get('(.*)', async ctx => {
const meta = await fetchMeta();
if (meta.privateMode) {
return;
}
await ctx.render('base', {
img: meta.bannerUrl,
title: meta.name || 'Misskey',
@ -533,7 +563,6 @@ 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,8 +51,6 @@ 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,18 +1,16 @@
extends ./base
block vars
- const title = privateMode ? instanceName : channel.name;
- const title = channel.name;
- const url = `${config.url}/channels/${channel.id}`;
block title
= `${title} | ${instanceName}`
block desc
unless privateMode
meta(name='description' content=channel.description)
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,18 +2,16 @@ extends ./base
block vars
- const user = clip.user;
- const title = privateMode ? instanceName : clip.name;
- const title = 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)
@ -21,7 +19,6 @@ block og
meta(property='og:image' content= avatarUrl)
block meta
unless privateMode
if profile.noCrawle
meta(name='robots' content='noindex')

View file

@ -2,18 +2,16 @@ extends ./base
block vars
- const user = post.user;
- const title = privateMode ? instanceName : post.title;
- const title = 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)
@ -21,7 +19,6 @@ 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 = privateMode ? instanceName : (user.name ? `${user.name} (@${user.username})` : `@${user.username}`);
- const title = 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,11 +10,9 @@ 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)
@ -22,7 +20,6 @@ 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,18 +2,16 @@ extends ./base
block vars
- const user = page.user;
- const title = privateMode ? instanceName : page.title;
- const title = 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)
@ -21,7 +19,6 @@ 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,18 +1,16 @@
extends ./base
block vars
- const title = privateMode ? instanceName : (user.name ? `${user.name} (@${user.username})` : `@${user.username}`);
- const title = 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)
@ -20,7 +18,6 @@ block og
meta(property='og:image' content= avatarUrl)
block meta
unless privateMode
if user.host || profile.noCrawle
meta(name='robots' content='noindex')