diff --git a/src/share/routes.js b/src/share/routes.js index 80fa3423f..a22691ce2 100644 --- a/src/share/routes.js +++ b/src/share/routes.js @@ -333,31 +333,31 @@ function register(router) { }); // Used for searching, require noteId so we know the subTreeRoot - router.get('/share/api/search/:noteId', (req, res, next) => { + router.get('/share/api/notes', (req, res, next) => { shacaLoader.ensureLoad(); + const ancestorNoteId = req.query.ancestorNoteId ?? "_share"; let note; - if (!(note = checkNoteAccess(req.params.noteId, req, res))) { + // This will automatically return if no ancestorNoteId is provided and there is no shareIndex + if (!(note = checkNoteAccess(ancestorNoteId, req, res))) { return; } - const {query} = req.query; + const {search} = req.query; - if (!query?.trim()) { - return res.status(400).json({ message: "'query' parameter is mandatory." }); + if (!search?.trim()) { + return res.status(400).json({ message: "'search' parameter is mandatory." }); } - const subRootPath = getSharedSubTreeRoot(note); - const subRoot = subRootPath.note; - const searchContext = new SearchContext({ancestorNoteId: subRoot.noteId}); - const searchResults = searchService.findResultsWithQuery(query, searchContext); + const searchContext = new SearchContext({ancestorNoteId: ancestorNoteId}); + const searchResults = searchService.findResultsWithQuery(search, searchContext); const filteredResults = searchResults.map(sr => { const fullNote = shaca.notes[sr.noteId]; - const startIndex = sr.notePathArray.indexOf(subRoot.noteId); - const localPathArray = sr.notePathArray.slice(startIndex + 1); + const startIndex = sr.notePathArray.indexOf(ancestorNoteId); + const localPathArray = sr.notePathArray.slice(startIndex + 1).filter(id => shaca.notes[id]); const pathTitle = localPathArray.map(id => shaca.notes[id].title).join(" / "); - return { id: fullNote.noteId, title: fullNote.title, score: sr.score, path: pathTitle }; + return { id: fullNote.shareId, title: fullNote.title, score: sr.score, path: pathTitle }; }); res.json({ results: filteredResults }); diff --git a/src/views/share/page.ejs b/src/views/share/page.ejs index 9d95a155a..8c6c3033d 100644 --- a/src/views/share/page.ejs +++ b/src/views/share/page.ejs @@ -32,7 +32,7 @@ <%- header %> <%= note.title %> - +
<% if (note.parents[0].noteId !== '_share' && note.parents.length !== 0) { %> diff --git a/src/views/share/tree_item.ejs b/src/views/share/tree_item.ejs index f139be8ac..995317036 100644 --- a/src/views/share/tree_item.ejs +++ b/src/views/share/tree_item.ejs @@ -2,7 +2,6 @@ const isExternalLink = note.hasLabel('shareExternalLink'); const linkHref = isExternalLink ? note.getLabelValue('shareExternalLink') : `./${note.shareId}`; const target = isExternalLink ? ` target="_blank" rel="noopener noreferrer"` : ''; -console.log(note.shareId, note.title, isExternalLink, linkHref, target); %>

<% const titleWithPrefix = (branch.prefix ? `${branch.prefix} - ` : '') + note.title; %>