1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

Api: Require token for search end point, fixed a few issues and added doc

This commit is contained in:
Laurent Cozic
2019-02-24 12:37:37 +00:00
parent 50b75e1e63
commit 1736717f2e
3 changed files with 19 additions and 1 deletions

View File

@@ -9,9 +9,19 @@ class SearchEngineUtils {
const results = await SearchEngine.instance().search(query);
const noteIds = results.map(n => n.id);
// We need at least the note ID to be able to sort them below so if not
// present in field list, add it.L Also remember it was auto-added so that
// it can be removed afterwards.
let idWasAutoAdded = false;
const fields = options.fields ? options.fields : Note.previewFields().slice();
if (fields.indexOf('id') < 0) {
fields.push('id');
idWasAutoAdded = true;
}
const previewOptions = Object.assign({}, {
order: [],
fields: Note.previewFields(),
fields: fields,
conditions: ['id IN ("' + noteIds.join('","') + '")'],
}, options);
@@ -24,6 +34,7 @@ class SearchEngineUtils {
for (let i = 0; i < notes.length; i++) {
const idx = noteIds.indexOf(notes[i].id);
sortedNotes[idx] = notes[i];
if (idWasAutoAdded) delete sortedNotes[idx].id;
}
return sortedNotes;

View File

@@ -209,6 +209,8 @@ class Api {
}
async action_search(request) {
this.checkToken_(request);
if (request.method !== 'GET') throw new ErrorMethodNotAllowed();
const query = request.query.query;