Skip rendering private data in privateMode
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:
parent
cce01c9a70
commit
e5595ca31c
8 changed files with 135 additions and 125 deletions
|
@ -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');
|
||||
});
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
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)
|
||||
meta(property='og:url' content= url)
|
||||
meta(property='og:image' content= channel.bannerUrl)
|
||||
meta(property='og:type' content='article')
|
||||
meta(property='og:title' content= title)
|
||||
meta(property='og:description' content= channel.description)
|
||||
meta(property='og:url' content= url)
|
||||
meta(property='og:image' content= channel.bannerUrl)
|
||||
|
|
|
@ -2,33 +2,30 @@ 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)
|
||||
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)
|
||||
meta(property='og:url' content= url)
|
||||
meta(property='og:image' content= avatarUrl)
|
||||
meta(property='og:type' content='article')
|
||||
meta(property='og:title' content= title)
|
||||
meta(property='og:description' content= clip.description)
|
||||
meta(property='og:url' content= url)
|
||||
meta(property='og:image' content= avatarUrl)
|
||||
|
||||
block meta
|
||||
unless privateMode
|
||||
if profile.noCrawle
|
||||
meta(name='robots' content='noindex')
|
||||
if profile.noCrawle
|
||||
meta(name='robots' content='noindex')
|
||||
|
||||
meta(name='misskey:user-username' content=user.username)
|
||||
meta(name='misskey:user-id' content=user.id)
|
||||
meta(name='misskey:clip-id' content=clip.id)
|
||||
meta(name='misskey:user-username' content=user.username)
|
||||
meta(name='misskey:user-id' content=user.id)
|
||||
meta(name='misskey:clip-id' content=clip.id)
|
||||
|
||||
// todo
|
||||
if user.twitter
|
||||
meta(name='twitter:creator' content=`@${user.twitter.screenName}`)
|
||||
// todo
|
||||
if user.twitter
|
||||
meta(name='twitter:creator' content=`@${user.twitter.screenName}`)
|
||||
|
|
|
@ -2,35 +2,32 @@ 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)
|
||||
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)
|
||||
meta(property='og:url' content= url)
|
||||
meta(property='og:image' content= post.files[0].thumbnailUrl)
|
||||
meta(property='og:type' content='article')
|
||||
meta(property='og:title' content= title)
|
||||
meta(property='og:description' content= post.description)
|
||||
meta(property='og:url' content= url)
|
||||
meta(property='og:image' content= post.files[0].thumbnailUrl)
|
||||
|
||||
block meta
|
||||
unless privateMode
|
||||
if user.host || profile.noCrawle
|
||||
meta(name='robots' content='noindex')
|
||||
if user.host || profile.noCrawle
|
||||
meta(name='robots' content='noindex')
|
||||
|
||||
meta(name='misskey:user-username' content=user.username)
|
||||
meta(name='misskey:user-id' content=user.id)
|
||||
meta(name='misskey:user-username' content=user.username)
|
||||
meta(name='misskey:user-id' content=user.id)
|
||||
|
||||
// todo
|
||||
if user.twitter
|
||||
meta(name='twitter:creator' content=`@${user.twitter.screenName}`)
|
||||
// todo
|
||||
if user.twitter
|
||||
meta(name='twitter:creator' content=`@${user.twitter.screenName}`)
|
||||
|
||||
if !user.host
|
||||
link(rel='alternate' href=url type='application/activity+json')
|
||||
if !user.host
|
||||
link(rel='alternate' href=url type='application/activity+json')
|
||||
|
|
|
@ -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,36 +10,33 @@ block title
|
|||
= `${title} | ${instanceName}`
|
||||
|
||||
block desc
|
||||
unless privateMode
|
||||
meta(name='description' content= summary)
|
||||
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)
|
||||
meta(property='og:url' content= url)
|
||||
meta(property='og:image' content= avatarUrl)
|
||||
meta(property='og:type' content='article')
|
||||
meta(property='og:title' content= title)
|
||||
meta(property='og:description' content= summary)
|
||||
meta(property='og:url' content= url)
|
||||
meta(property='og:image' content= avatarUrl)
|
||||
|
||||
block meta
|
||||
unless privateMode
|
||||
if user.host || isRenote || profile.noCrawle
|
||||
meta(name='robots' content='noindex')
|
||||
if user.host || isRenote || profile.noCrawle
|
||||
meta(name='robots' content='noindex')
|
||||
|
||||
meta(name='misskey:user-username' content=user.username)
|
||||
meta(name='misskey:user-id' content=user.id)
|
||||
meta(name='misskey:note-id' content=note.id)
|
||||
meta(name='misskey:user-username' content=user.username)
|
||||
meta(name='misskey:user-id' content=user.id)
|
||||
meta(name='misskey:note-id' content=note.id)
|
||||
|
||||
// todo
|
||||
if user.twitter
|
||||
meta(name='twitter:creator' content=`@${user.twitter.screenName}`)
|
||||
|
||||
// todo
|
||||
if user.twitter
|
||||
meta(name='twitter:creator' content=`@${user.twitter.screenName}`)
|
||||
if note.prev
|
||||
link(rel='prev' href=`${config.url}/notes/${note.prev}`)
|
||||
if note.next
|
||||
link(rel='next' href=`${config.url}/notes/${note.next}`)
|
||||
|
||||
if note.prev
|
||||
link(rel='prev' href=`${config.url}/notes/${note.prev}`)
|
||||
if note.next
|
||||
link(rel='next' href=`${config.url}/notes/${note.next}`)
|
||||
|
||||
if !user.host
|
||||
link(rel='alternate' href=url type='application/activity+json')
|
||||
if note.uri
|
||||
link(rel='alternate' href=note.uri type='application/activity+json')
|
||||
if !user.host
|
||||
link(rel='alternate' href=url type='application/activity+json')
|
||||
if note.uri
|
||||
link(rel='alternate' href=note.uri type='application/activity+json')
|
||||
|
|
|
@ -2,33 +2,30 @@ 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)
|
||||
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)
|
||||
meta(property='og:url' content= url)
|
||||
meta(property='og:image' content= page.eyeCatchingImage ? page.eyeCatchingImage.thumbnailUrl : avatarUrl)
|
||||
meta(property='og:type' content='article')
|
||||
meta(property='og:title' content= title)
|
||||
meta(property='og:description' content= page.summary)
|
||||
meta(property='og:url' content= url)
|
||||
meta(property='og:image' content= page.eyeCatchingImage ? page.eyeCatchingImage.thumbnailUrl : avatarUrl)
|
||||
|
||||
block meta
|
||||
unless privateMode
|
||||
if profile.noCrawle
|
||||
meta(name='robots' content='noindex')
|
||||
if profile.noCrawle
|
||||
meta(name='robots' content='noindex')
|
||||
|
||||
meta(name='misskey:user-username' content=user.username)
|
||||
meta(name='misskey:user-id' content=user.id)
|
||||
meta(name='misskey:page-id' content=page.id)
|
||||
meta(name='misskey:user-username' content=user.username)
|
||||
meta(name='misskey:user-id' content=user.id)
|
||||
meta(name='misskey:page-id' content=page.id)
|
||||
|
||||
// todo
|
||||
if user.twitter
|
||||
meta(name='twitter:creator' content=`@${user.twitter.screenName}`)
|
||||
// todo
|
||||
if user.twitter
|
||||
meta(name='twitter:creator' content=`@${user.twitter.screenName}`)
|
||||
|
|
|
@ -1,42 +1,39 @@
|
|||
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)
|
||||
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)
|
||||
meta(property='og:url' content= url)
|
||||
meta(property='og:image' content= avatarUrl)
|
||||
meta(property='og:type' content='blog')
|
||||
meta(property='og:title' content= title)
|
||||
meta(property='og:description' content= profile.description)
|
||||
meta(property='og:url' content= url)
|
||||
meta(property='og:image' content= avatarUrl)
|
||||
|
||||
block meta
|
||||
unless privateMode
|
||||
if user.host || profile.noCrawle
|
||||
meta(name='robots' content='noindex')
|
||||
if user.host || profile.noCrawle
|
||||
meta(name='robots' content='noindex')
|
||||
|
||||
meta(name='misskey:user-username' content=user.username)
|
||||
meta(name='misskey:user-id' content=user.id)
|
||||
meta(name='misskey:user-username' content=user.username)
|
||||
meta(name='misskey:user-id' content=user.id)
|
||||
|
||||
if profile.twitter
|
||||
meta(name='twitter:creator' content=`@${profile.twitter.screenName}`)
|
||||
if profile.twitter
|
||||
meta(name='twitter:creator' content=`@${profile.twitter.screenName}`)
|
||||
|
||||
if !sub
|
||||
if !user.host
|
||||
link(rel='alternate' href=`${config.url}/users/${user.id}` type='application/activity+json')
|
||||
if user.uri
|
||||
link(rel='alternate' href=user.uri type='application/activity+json')
|
||||
if profile.url
|
||||
link(rel='alternate' href=profile.url type='text/html')
|
||||
if !sub
|
||||
if !user.host
|
||||
link(rel='alternate' href=`${config.url}/users/${user.id}` type='application/activity+json')
|
||||
if user.uri
|
||||
link(rel='alternate' href=user.uri type='application/activity+json')
|
||||
if profile.url
|
||||
link(rel='alternate' href=profile.url type='text/html')
|
||||
|
||||
each m in me
|
||||
link(rel='me' href=`${m}`)
|
||||
each m in me
|
||||
link(rel='me' href=`${m}`)
|
||||
|
|
Loading…
Reference in a new issue