From 67cb02ed922bce7b2621a79d1ab71037eba2018f Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 17 Apr 2024 22:54:05 +0300 Subject: [PATCH] server-ts: Address some more review comments --- src/share/routes.ts | 20 +++++++++----------- src/share/shaca/entities/snote.ts | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/share/routes.ts b/src/share/routes.ts index ccac51295..97a0dd8e1 100644 --- a/src/share/routes.ts +++ b/src/share/routes.ts @@ -1,8 +1,8 @@ -import express = require('express'); -import path = require('path'); import safeCompare = require('safe-compare'); import ejs = require("ejs"); +import type { Request, Response, Router } from "express"; + import shaca = require('./shaca/shaca'); import shacaLoader = require('./shaca/shaca_loader'); import shareRoot = require('./share_root'); @@ -15,8 +15,6 @@ import log = require('../services/log'); import SNote = require('./shaca/entities/snote'); import SBranch = require('./shaca/entities/sbranch'); import SAttachment = require('./shaca/entities/sattachment'); -import BNote = require('../becca/entities/bnote'); -import BRevision = require('../becca/entities/brevision'); function getSharedSubTreeRoot(note: SNote): { note?: SNote; branch?: SBranch } { if (note.noteId === shareRoot.SHARE_ROOT_NOTE_ID) { @@ -38,18 +36,18 @@ function getSharedSubTreeRoot(note: SNote): { note?: SNote; branch?: SBranch } { return getSharedSubTreeRoot(parentBranch.getParentNote()); } -function addNoIndexHeader(note: SNote, res: express.Response) { +function addNoIndexHeader(note: SNote, res: Response) { if (note.isLabelTruthy('shareDisallowRobotIndexing')) { res.setHeader('X-Robots-Tag', 'noindex'); } } -function requestCredentials(res: express.Response) { +function requestCredentials(res: Response) { res.setHeader('WWW-Authenticate', 'Basic realm="User Visible Realm", charset="UTF-8"') .sendStatus(401); } -function checkAttachmentAccess(attachmentId: string, req: express.Request, res: express.Response) { +function checkAttachmentAccess(attachmentId: string, req: Request, res: Response) { const attachment = shaca.getAttachment(attachmentId); if (!attachment) { @@ -65,7 +63,7 @@ function checkAttachmentAccess(attachmentId: string, req: express.Request, res: return note ? attachment : false; } -function checkNoteAccess(noteId: string, req: express.Request, res: express.Response) { +function checkNoteAccess(noteId: string, req: Request, res: Response) { const note = shaca.getNote(noteId); if (!note) { @@ -108,7 +106,7 @@ function checkNoteAccess(noteId: string, req: express.Request, res: express.Resp return false; } -function renderImageAttachment(image: SNote, res: express.Response, attachmentName: string) { +function renderImageAttachment(image: SNote, res: Response, attachmentName: string) { let svgString = '' const attachment = image.getAttachmentByTitle(attachmentName); if (!attachment) { @@ -133,8 +131,8 @@ function renderImageAttachment(image: SNote, res: express.Response, attachmentNa res.send(svg); } -function register(router: express.Router) { - function renderNote(note: SNote, req: express.Request, res: express.Response) { +function register(router: Router) { + function renderNote(note: SNote, req: Request, res: Response) { if (!note) { res.status(404).render("share/404"); return; diff --git a/src/share/shaca/entities/snote.ts b/src/share/shaca/entities/snote.ts index 3ca182167..bae610886 100644 --- a/src/share/shaca/entities/snote.ts +++ b/src/share/shaca/entities/snote.ts @@ -169,7 +169,7 @@ class SNote extends AbstractShacaEntity { } } - const templateAttributes = []; + const templateAttributes: SAttribute[] = []; for (const ownedAttr of parentAttributes) { // parentAttributes so we process also inherited templates if (ownedAttr.type === 'relation' && ['template', 'inherit'].includes(ownedAttr.name)) {