enhance: only render public notes in HTML template (#8527)

* only render public notes in HTML template

* fix missing import
This commit is contained in:
Johann150 2022-04-24 07:17:09 +02:00 committed by GitHub
parent 1b2ba09be0
commit 7e28c396b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,7 +14,7 @@ import { createBullBoard } from '@bull-board/api';
import { BullAdapter } from '@bull-board/api/bullAdapter.js'; import { BullAdapter } from '@bull-board/api/bullAdapter.js';
import { KoaAdapter } from '@bull-board/koa'; import { KoaAdapter } from '@bull-board/koa';
import { IsNull } from 'typeorm'; import { In, IsNull } from 'typeorm';
import { fetchMeta } from '@/misc/fetch-meta.js'; import { fetchMeta } from '@/misc/fetch-meta.js';
import config from '@/config/index.js'; import config from '@/config/index.js';
import { Users, Notes, UserProfiles, Pages, Channels, Clips, GalleryPosts } from '@/models/index.js'; import { Users, Notes, UserProfiles, Pages, Channels, Clips, GalleryPosts } from '@/models/index.js';
@ -266,7 +266,10 @@ router.get('/users/:user', async ctx => {
// Note // Note
router.get('/notes/:note', async (ctx, next) => { router.get('/notes/:note', async (ctx, next) => {
const note = await Notes.findOneBy({ id: ctx.params.note }); const note = await Notes.findOneBy({
id: ctx.params.note,
visibility: In(['public', 'home']),
});
if (note) { if (note) {
const _note = await Notes.pack(note); const _note = await Notes.pack(note);
@ -283,11 +286,7 @@ router.get('/notes/:note', async (ctx, next) => {
themeColor: meta.themeColor, themeColor: meta.themeColor,
}); });
if (['public', 'home'].includes(note.visibility)) {
ctx.set('Cache-Control', 'public, max-age=180'); ctx.set('Cache-Control', 'public, max-age=180');
} else {
ctx.set('Cache-Control', 'private, max-age=0, must-revalidate');
}
return; return;
} }