mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
server-ts: Port share/share_root
This commit is contained in:
parent
80a1b8b44d
commit
b07df6061f
@ -1,7 +1,7 @@
|
|||||||
const {JSDOM} = require("jsdom");
|
const { JSDOM } = require("jsdom");
|
||||||
const shaca = require('./shaca/shaca.js');
|
const shaca = require('./shaca/shaca.js');
|
||||||
const assetPath = require('../services/asset_path');
|
const assetPath = require('../services/asset_path');
|
||||||
const shareRoot = require('./share_root.js');
|
const shareRoot = require('./share_root');
|
||||||
const escapeHtml = require('escape-html');
|
const escapeHtml = require('escape-html');
|
||||||
|
|
||||||
function getContent(note) {
|
function getContent(note) {
|
||||||
|
@ -5,7 +5,7 @@ const ejs = require("ejs");
|
|||||||
|
|
||||||
const shaca = require('./shaca/shaca.js');
|
const shaca = require('./shaca/shaca.js');
|
||||||
const shacaLoader = require('./shaca/shaca_loader.js');
|
const shacaLoader = require('./shaca/shaca_loader.js');
|
||||||
const shareRoot = require('./share_root.js');
|
const shareRoot = require('./share_root');
|
||||||
const contentRenderer = require('./content_renderer.js');
|
const contentRenderer = require('./content_renderer.js');
|
||||||
const assetPath = require('../services/asset_path');
|
const assetPath = require('../services/asset_path');
|
||||||
const appPath = require('../services/app_path');
|
const appPath = require('../services/app_path');
|
||||||
@ -152,9 +152,9 @@ function register(router) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {header, content, isEmpty} = contentRenderer.getContent(note);
|
const { header, content, isEmpty } = contentRenderer.getContent(note);
|
||||||
const subRoot = getSharedSubTreeRoot(note);
|
const subRoot = getSharedSubTreeRoot(note);
|
||||||
const opts = {note, header, content, isEmpty, subRoot, assetPath, appPath};
|
const opts = { note, header, content, isEmpty, subRoot, assetPath, appPath };
|
||||||
let useDefaultView = true;
|
let useDefaultView = true;
|
||||||
|
|
||||||
// Check if the user has their own template
|
// Check if the user has their own template
|
||||||
@ -176,7 +176,7 @@ function register(router) {
|
|||||||
|
|
||||||
// Try to render user's template, w/ fallback to default view
|
// Try to render user's template, w/ fallback to default view
|
||||||
try {
|
try {
|
||||||
const ejsResult = ejs.render(templateNote.getContent(), opts, {includer});
|
const ejsResult = ejs.render(templateNote.getContent(), opts, { includer });
|
||||||
res.send(ejsResult);
|
res.send(ejsResult);
|
||||||
useDefaultView = false; // Rendering went okay, don't use default view
|
useDefaultView = false; // Rendering went okay, don't use default view
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ function register(router) {
|
|||||||
router.get('/share/:shareId', (req, res, next) => {
|
router.get('/share/:shareId', (req, res, next) => {
|
||||||
shacaLoader.ensureLoad();
|
shacaLoader.ensureLoad();
|
||||||
|
|
||||||
const {shareId} = req.params;
|
const { shareId } = req.params;
|
||||||
|
|
||||||
const note = shaca.aliasToNote[shareId] || shaca.notes[shareId];
|
const note = shaca.aliasToNote[shareId] || shaca.notes[shareId];
|
||||||
|
|
||||||
@ -346,13 +346,13 @@ function register(router) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {search} = req.query;
|
const { search } = req.query;
|
||||||
|
|
||||||
if (!search?.trim()) {
|
if (!search?.trim()) {
|
||||||
return res.status(400).json({ message: "'search' parameter is mandatory." });
|
return res.status(400).json({ message: "'search' parameter is mandatory." });
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchContext = new SearchContext({ancestorNoteId: ancestorNoteId});
|
const searchContext = new SearchContext({ ancestorNoteId: ancestorNoteId });
|
||||||
const searchResults = searchService.findResultsWithQuery(search, searchContext);
|
const searchResults = searchService.findResultsWithQuery(search, searchContext);
|
||||||
const filteredResults = searchResults.map(sr => {
|
const filteredResults = searchResults.map(sr => {
|
||||||
const fullNote = shaca.notes[sr.noteId];
|
const fullNote = shaca.notes[sr.noteId];
|
||||||
|
@ -7,7 +7,7 @@ const SNote = require('./entities/snote.js');
|
|||||||
const SBranch = require('./entities/sbranch.js');
|
const SBranch = require('./entities/sbranch.js');
|
||||||
const SAttribute = require('./entities/sattribute.js');
|
const SAttribute = require('./entities/sattribute.js');
|
||||||
const SAttachment = require('./entities/sattachment.js');
|
const SAttachment = require('./entities/sattachment.js');
|
||||||
const shareRoot = require('../share_root.js');
|
const shareRoot = require('../share_root');
|
||||||
const eventService = require('../../services/events');
|
const eventService = require('../../services/events');
|
||||||
|
|
||||||
function load() {
|
function load() {
|
||||||
@ -89,7 +89,7 @@ function ensureLoad() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eventService.subscribe([ eventService.ENTITY_CREATED, eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED, eventService.ENTITY_CHANGE_SYNCED, eventService.ENTITY_DELETE_SYNCED ], ({ entityName, entity }) => {
|
eventService.subscribe([eventService.ENTITY_CREATED, eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED, eventService.ENTITY_CHANGE_SYNCED, eventService.ENTITY_DELETE_SYNCED], ({ entityName, entity }) => {
|
||||||
shaca.reset();
|
shaca.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
module.exports = {
|
export = {
|
||||||
SHARE_ROOT_NOTE_ID: '_share'
|
SHARE_ROOT_NOTE_ID: '_share'
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user