trilium/src/routes/api/tree.js

62 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-10-22 09:10:33 +08:00
"use strict";
2017-10-16 07:47:05 +08:00
const sql = require('../../services/sql');
const optionService = require('../../services/options');
const protectedSessionService = require('../../services/protected_session');
async function getTree() {
2018-03-25 09:39:15 +08:00
const branches = await sql.getRows(`
SELECT
2018-03-25 09:39:15 +08:00
branchId,
noteId,
parentNoteId,
notePosition,
prefix,
isExpanded
FROM
2018-03-25 09:39:15 +08:00
branches
WHERE
isDeleted = 0
ORDER BY
2018-01-29 08:30:14 +08:00
notePosition`);
2018-03-31 00:57:22 +08:00
const notes = [{
noteId: 'root',
title: 'root',
isProtected: false,
type: 'none',
mime: 'none'
2018-03-31 00:57:22 +08:00
}].concat(await sql.getRows(`
SELECT
notes.noteId,
notes.title,
notes.isProtected,
notes.type,
notes.mime,
hideInAutocomplete.labelId AS 'hideInAutocomplete'
FROM
notes
LEFT JOIN labels AS hideInAutocomplete ON hideInAutocomplete.noteId = notes.noteId
2018-04-03 09:56:55 +08:00
AND hideInAutocomplete.name = 'hideInAutocomplete'
AND hideInAutocomplete.isDeleted = 0
WHERE
notes.isDeleted = 0`));
protectedSessionService.decryptNotes(notes);
notes.forEach(note => {
note.hideInAutocomplete = !!note.hideInAutocomplete;
note.isProtected = !!note.isProtected;
});
2018-03-31 00:57:22 +08:00
return {
2018-04-03 09:47:46 +08:00
startNotePath: await optionService.getOption('startNotePath'),
2018-03-25 09:39:15 +08:00
branches: branches,
2018-04-03 09:34:28 +08:00
notes: notes
2018-03-31 00:57:22 +08:00
};
}
2018-03-31 00:57:22 +08:00
module.exports = {
2018-04-02 08:33:10 +08:00
getTree
2018-03-31 00:57:22 +08:00
};