mirror of
https://github.com/zadam/trilium.git
synced 2025-11-03 03:46:37 +01:00
saved search can now be created from the search dialog
This commit is contained in:
35
src/routes/api/search.js
Normal file
35
src/routes/api/search.js
Normal file
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const auth = require('../../services/auth');
|
||||
const sql = require('../../services/sql');
|
||||
const notes = require('../../services/notes');
|
||||
const wrap = require('express-promise-wrap').wrap;
|
||||
const parseFilters = require('../../services/parse_filters');
|
||||
const buildSearchQuery = require('../../services/build_search_query');
|
||||
|
||||
router.get('/:searchString', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
const {attrFilters, searchText} = parseFilters(req.params.searchString);
|
||||
|
||||
const {query, params} = buildSearchQuery(attrFilters, searchText);
|
||||
|
||||
const noteIds = await sql.getColumn(query, params);
|
||||
|
||||
res.send(noteIds);
|
||||
}));
|
||||
|
||||
router.post('/:searchString', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
const noteContent = {
|
||||
searchString: req.params.searchString
|
||||
};
|
||||
|
||||
const noteId = await notes.createNote('root', 'Search note', noteContent, {
|
||||
json: true,
|
||||
type: 'search'
|
||||
});
|
||||
|
||||
res.send({ noteId });
|
||||
}));
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user