Skip to content

Commit 520d83f

Browse files
committed
notes updating
1 parent 654bc56 commit 520d83f

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

backend/src/routes/raw.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import express, {Router} from "express";
2-
import {checkUser, hasPermissions, noteCache} from "../utils";
2+
import {checkUser, getNote, hasPermissions} from "../utils";
33
import {COLLECTION_IMAGE_STORE, COLLECTION_NOTES_STORE, USERS_STORE} from "../storage";
44
import {
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

backend/src/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff 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 [];

0 commit comments

Comments
 (0)