mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	server-ts: Address some more review comments
This commit is contained in:
		
							parent
							
								
									1d1ccc8d63
								
							
						
					
					
						commit
						67cb02ed92
					
				@ -1,8 +1,8 @@
 | 
				
			|||||||
import express = require('express');
 | 
					 | 
				
			||||||
import path = require('path');
 | 
					 | 
				
			||||||
import safeCompare = require('safe-compare');
 | 
					import safeCompare = require('safe-compare');
 | 
				
			||||||
import ejs = require("ejs");
 | 
					import ejs = require("ejs");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import type { Request, Response, Router } from "express";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import shaca = require('./shaca/shaca');
 | 
					import shaca = require('./shaca/shaca');
 | 
				
			||||||
import shacaLoader = require('./shaca/shaca_loader');
 | 
					import shacaLoader = require('./shaca/shaca_loader');
 | 
				
			||||||
import shareRoot = require('./share_root');
 | 
					import shareRoot = require('./share_root');
 | 
				
			||||||
@ -15,8 +15,6 @@ import log = require('../services/log');
 | 
				
			|||||||
import SNote = require('./shaca/entities/snote');
 | 
					import SNote = require('./shaca/entities/snote');
 | 
				
			||||||
import SBranch = require('./shaca/entities/sbranch');
 | 
					import SBranch = require('./shaca/entities/sbranch');
 | 
				
			||||||
import SAttachment = require('./shaca/entities/sattachment');
 | 
					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 } {
 | 
					function getSharedSubTreeRoot(note: SNote): { note?: SNote; branch?: SBranch } {
 | 
				
			||||||
    if (note.noteId === shareRoot.SHARE_ROOT_NOTE_ID) {
 | 
					    if (note.noteId === shareRoot.SHARE_ROOT_NOTE_ID) {
 | 
				
			||||||
@ -38,18 +36,18 @@ function getSharedSubTreeRoot(note: SNote): { note?: SNote; branch?: SBranch } {
 | 
				
			|||||||
    return getSharedSubTreeRoot(parentBranch.getParentNote());
 | 
					    return getSharedSubTreeRoot(parentBranch.getParentNote());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function addNoIndexHeader(note: SNote, res: express.Response) {
 | 
					function addNoIndexHeader(note: SNote, res: Response) {
 | 
				
			||||||
    if (note.isLabelTruthy('shareDisallowRobotIndexing')) {
 | 
					    if (note.isLabelTruthy('shareDisallowRobotIndexing')) {
 | 
				
			||||||
        res.setHeader('X-Robots-Tag', 'noindex');
 | 
					        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"')
 | 
					    res.setHeader('WWW-Authenticate', 'Basic realm="User Visible Realm", charset="UTF-8"')
 | 
				
			||||||
        .sendStatus(401);
 | 
					        .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);
 | 
					    const attachment = shaca.getAttachment(attachmentId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!attachment) {
 | 
					    if (!attachment) {
 | 
				
			||||||
@ -65,7 +63,7 @@ function checkAttachmentAccess(attachmentId: string, req: express.Request, res:
 | 
				
			|||||||
    return note ? attachment : false;
 | 
					    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);
 | 
					    const note = shaca.getNote(noteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!note) {
 | 
					    if (!note) {
 | 
				
			||||||
@ -108,7 +106,7 @@ function checkNoteAccess(noteId: string, req: express.Request, res: express.Resp
 | 
				
			|||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function renderImageAttachment(image: SNote, res: express.Response, attachmentName: string) {
 | 
					function renderImageAttachment(image: SNote, res: Response, attachmentName: string) {
 | 
				
			||||||
    let svgString = '<svg/>'
 | 
					    let svgString = '<svg/>'
 | 
				
			||||||
    const attachment = image.getAttachmentByTitle(attachmentName);
 | 
					    const attachment = image.getAttachmentByTitle(attachmentName);
 | 
				
			||||||
    if (!attachment) {
 | 
					    if (!attachment) {
 | 
				
			||||||
@ -133,8 +131,8 @@ function renderImageAttachment(image: SNote, res: express.Response, attachmentNa
 | 
				
			|||||||
    res.send(svg);
 | 
					    res.send(svg);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function register(router: express.Router) {
 | 
					function register(router: Router) {
 | 
				
			||||||
    function renderNote(note: SNote, req: express.Request, res: express.Response) {
 | 
					    function renderNote(note: SNote, req: Request, res: Response) {
 | 
				
			||||||
        if (!note) {
 | 
					        if (!note) {
 | 
				
			||||||
            res.status(404).render("share/404");
 | 
					            res.status(404).render("share/404");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
 | 
				
			|||||||
@ -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
 | 
					            for (const ownedAttr of parentAttributes) { // parentAttributes so we process also inherited templates
 | 
				
			||||||
                if (ownedAttr.type === 'relation' && ['template', 'inherit'].includes(ownedAttr.name)) {
 | 
					                if (ownedAttr.type === 'relation' && ['template', 'inherit'].includes(ownedAttr.name)) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user