File tree Expand file tree Collapse file tree 2 files changed +6
-5
lines changed
Expand file tree Collapse file tree 2 files changed +6
-5
lines changed Original file line number Diff line number Diff line change 11import express , { Router } from "express" ;
2- import { checkUser , hasPermissions , noteCache } from "../utils" ;
2+ import { checkUser , getNote , hasPermissions } from "../utils" ;
33import { COLLECTION_IMAGE_STORE , COLLECTION_NOTES_STORE , USERS_STORE } from "../storage" ;
44import {
55 COLLECTION_IMAGE_PATH ,
@@ -33,8 +33,8 @@ export async function noteHandler(req: express.Request, res: express.Response) {
3333 const r = COLLECTION_NOTES_STORE . read ( COLLECTION_NOTE_PATH ( req . params . cid , req . params . nid ) ) ;
3434 res . set ( 'Cache-control' , `public, max-age=${ CACHE_TIME } ` ) ;
3535 if ( r ) return r ?. pipe ( res ) ;
36- const note = noteCache . get ( req . params . cid ) ?. find ( n => n . nid === req . params . nid ) ;
37- if ( note ?. url && note . url !== COLLECTION_NOTE_URL ( note . cid , note . nid ) ) return res . redirect ( note . url ) ;
36+ const note = await getNote ( req . params . cid , req . params . nid ) ;
37+ if ( note ?. url && note ? .url !== COLLECTION_NOTE_URL ( note . cid , note . nid ) ) return res . redirect ( note . url ) ;
3838 else return res . sendStatus ( 404 ) ;
3939}
4040
Original file line number Diff line number Diff line change @@ -99,12 +99,13 @@ export function updateRoleCache(rid: string, value?: Role) {
9999 else roleCache . del ( rid ) ;
100100}
101101
102- export async function getNote ( cid : string , nid : string ) : Promise < Note | undefined > {
102+ export async function getNote ( cid ? : string , nid ? : string ) : Promise < Note | undefined > {
103103 let notes = await getNotes ( cid ) ;
104104 if ( notes ) return notes . find ( note => note . nid === nid ) ;
105105}
106106
107- export async function getNotes ( cid : string ) : Promise < Note [ ] | undefined > {
107+ export async function getNotes ( cid ?: string ) : Promise < Note [ ] | undefined > {
108+ if ( ! cid ) return undefined ;
108109 if ( noteCache . has ( cid ) ) return noteCache . get ( cid ) ;
109110 else {
110111 if ( ! collectionCache . get ( cid ) ) return [ ] ;
You can’t perform that action at this time.
0 commit comments