mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	Adjust shared notes search api
This commit is contained in:
		| @@ -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 }); | ||||
|   | ||||
| @@ -32,7 +32,7 @@ | ||||
|     <%- header %> | ||||
|     <title><%= note.title %></title> | ||||
| </head> | ||||
| <body data-note-id="<%= note.noteId %>" data-wtf="true"> | ||||
| <body data-note-id="<%= note.noteId %>" data-ancestor-note-id="<%= subRoot.note.noteId %>"> | ||||
| <div id="layout"> | ||||
|     <div id="main"> | ||||
|         <% if (note.parents[0].noteId !== '_share' && note.parents.length !== 0) { %> | ||||
|   | ||||
| @@ -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); | ||||
| %> | ||||
| <p> | ||||
|     <% const titleWithPrefix = (branch.prefix ? `${branch.prefix} - ` : '') + note.title; %> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user