trilium/src/routes/api/tree.js

64 lines
1.6 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 config = require('../../services/config');
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
AND hideInAutocomplete.name = 'hide_in_autocomplete'
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 {
instanceName: config.General ? config.General.instanceName : null,
2018-03-25 09:39:15 +08:00
branches: branches,
notes: notes,
start_note_path: await optionService.getOption('start_note_path')
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
};