mirror of
https://github.com/zadam/trilium.git
synced 2025-11-13 08:45:50 +01:00
becca conversion WIP
This commit is contained in:
@@ -8,7 +8,7 @@ const Attribute = require('../../entities/attribute');
|
||||
const becca = require("../../services/becca/becca.js");
|
||||
|
||||
function getEffectiveNoteAttributes(req) {
|
||||
const note = repository.getNote(req.params.noteId);
|
||||
const note = becca.getNote(req.params.noteId);
|
||||
|
||||
return note.getAttributes();
|
||||
}
|
||||
@@ -19,7 +19,7 @@ function updateNoteAttribute(req) {
|
||||
|
||||
let attribute;
|
||||
if (body.attributeId) {
|
||||
attribute = repository.getAttribute(body.attributeId);
|
||||
attribute = becca.getAttribute(body.attributeId);
|
||||
|
||||
if (attribute.noteId !== noteId) {
|
||||
return [400, `Attribute ${body.attributeId} is not owned by ${noteId}`];
|
||||
@@ -116,7 +116,7 @@ function updateNoteAttributes(req) {
|
||||
const noteId = req.params.noteId;
|
||||
const incomingAttributes = req.body;
|
||||
|
||||
const note = repository.getNote(noteId);
|
||||
const note = becca.getNote(noteId);
|
||||
|
||||
let existingAttrs = note.getOwnedAttributes();
|
||||
|
||||
@@ -143,7 +143,7 @@ function updateNoteAttributes(req) {
|
||||
}
|
||||
|
||||
if (incAttr.type === 'relation') {
|
||||
const targetNote = repository.getNote(incAttr.value);
|
||||
const targetNote = becca.getNote(incAttr.value);
|
||||
|
||||
if (!targetNote || targetNote.isDeleted) {
|
||||
log.error(`Target note of relation ${JSON.stringify(incAttr)} does not exist or is deleted`);
|
||||
|
||||
@@ -17,8 +17,8 @@ const TaskContext = require('../../services/task_context');
|
||||
function moveBranchToParent(req) {
|
||||
const {branchId, parentBranchId} = req.params;
|
||||
|
||||
const parentBranch = repository.getBranch(parentBranchId);
|
||||
const branchToMove = repository.getBranch(branchId);
|
||||
const parentBranch = becca.getBranch(parentBranchId);
|
||||
const branchToMove = becca.getBranch(branchId);
|
||||
|
||||
if (!parentBranch || !branchToMove) {
|
||||
return [400, `One or both branches ${branchId}, ${parentBranchId} have not been found`];
|
||||
@@ -53,8 +53,8 @@ function moveBranchToParent(req) {
|
||||
function moveBranchBeforeNote(req) {
|
||||
const {branchId, beforeBranchId} = req.params;
|
||||
|
||||
const branchToMove = repository.getBranch(branchId);
|
||||
const beforeBranch = repository.getBranch(beforeBranchId);
|
||||
const branchToMove = becca.getBranch(branchId);
|
||||
const beforeBranch = becca.getBranch(beforeBranchId);
|
||||
|
||||
if (!branchToMove) {
|
||||
return [404, `Can't find branch ${branchId}`];
|
||||
@@ -95,8 +95,8 @@ function moveBranchBeforeNote(req) {
|
||||
function moveBranchAfterNote(req) {
|
||||
const {branchId, afterBranchId} = req.params;
|
||||
|
||||
const branchToMove = repository.getBranch(branchId);
|
||||
const afterNote = repository.getBranch(afterBranchId);
|
||||
const branchToMove = becca.getBranch(branchId);
|
||||
const afterNote = becca.getBranch(afterBranchId);
|
||||
|
||||
const validationResult = treeService.validateParentChild(afterNote.parentNoteId, branchToMove.noteId, branchId);
|
||||
|
||||
@@ -180,7 +180,7 @@ function setExpandedForSubtree(req) {
|
||||
|
||||
function deleteBranch(req) {
|
||||
const last = req.query.last === 'true';
|
||||
const branch = repository.getBranch(req.params.branchId);
|
||||
const branch = becca.getBranch(req.params.branchId);
|
||||
const taskContext = TaskContext.getInstance(req.query.taskId, 'delete-notes');
|
||||
|
||||
const deleteId = utils.randomString(10);
|
||||
@@ -199,7 +199,7 @@ function setPrefix(req) {
|
||||
const branchId = req.params.branchId;
|
||||
const prefix = utils.isEmptyOrWhitespace(req.body.prefix) ? null : req.body.prefix;
|
||||
|
||||
const branch = repository.getBranch(branchId);
|
||||
const branch = becca.getBranch(branchId);
|
||||
branch.prefix = prefix;
|
||||
branch.save();
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ function createSearchNote(req) {
|
||||
|
||||
function getHoistedNote() {
|
||||
return cls.getHoistedNoteId() && cls.getHoistedNoteId() !== 'root'
|
||||
? repository.getNote(cls.getHoistedNoteId())
|
||||
? becca.getNote(cls.getHoistedNoteId())
|
||||
: null;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ const log = require("../../services/log");
|
||||
|
||||
function exportBranch(req, res) {
|
||||
const {branchId, type, format, version, taskId} = req.params;
|
||||
const branch = repository.getBranch(branchId);
|
||||
const branch = becca.getBranch(branchId);
|
||||
|
||||
if (!branch) {
|
||||
const message = `Cannot export branch ${branchId} since it does not exist.`;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
const protectedSessionService = require('../../services/protected_session');
|
||||
const repository = require('../../services/repository');
|
||||
const utils = require('../../services/utils');
|
||||
const log = require('../../services/log');
|
||||
const noteRevisionService = require('../../services/note_revisions');
|
||||
@@ -10,12 +9,13 @@ const fs = require('fs');
|
||||
const { Readable } = require('stream');
|
||||
const chokidar = require('chokidar');
|
||||
const ws = require('../../services/ws');
|
||||
const becca = require("../../services/becca/becca.js");
|
||||
|
||||
function updateFile(req) {
|
||||
const {noteId} = req.params;
|
||||
const file = req.file;
|
||||
|
||||
const note = repository.getNote(noteId);
|
||||
const note = becca.getNote(noteId);
|
||||
|
||||
if (!note) {
|
||||
return [404, `Note ${noteId} doesn't exist.`];
|
||||
@@ -44,7 +44,7 @@ function getFilename(note) {
|
||||
}
|
||||
|
||||
function downloadNoteFile(noteId, res, contentDisposition = true) {
|
||||
const note = repository.getNote(noteId);
|
||||
const note = becca.getNote(noteId);
|
||||
|
||||
if (!note) {
|
||||
return res.status(404).send(`Note ${noteId} doesn't exist.`);
|
||||
@@ -79,7 +79,7 @@ function openFile(req, res) {
|
||||
|
||||
function fileContentProvider(req) {
|
||||
// Read file name from route params.
|
||||
const note = repository.getNote(req.params.noteId);
|
||||
const note = becca.getNote(req.params.noteId);
|
||||
const fileName = getFilename(note);
|
||||
let content = note.getContent();
|
||||
|
||||
@@ -112,7 +112,7 @@ function fileContentProvider(req) {
|
||||
function saveToTmpDir(req) {
|
||||
const noteId = req.params.noteId;
|
||||
|
||||
const note = repository.getNote(noteId);
|
||||
const note = becca.getNote(noteId);
|
||||
|
||||
if (!note) {
|
||||
return [404,`Note ${noteId} doesn't exist.`];
|
||||
|
||||
@@ -6,7 +6,7 @@ const RESOURCE_DIR = require('../../services/resource_dir').RESOURCE_DIR;
|
||||
const fs = require('fs');
|
||||
|
||||
function returnImage(req, res) {
|
||||
const image = repository.getNote(req.params.noteId);
|
||||
const image = becca.getNote(req.params.noteId);
|
||||
|
||||
if (!image) {
|
||||
return res.sendStatus(404);
|
||||
@@ -28,7 +28,7 @@ function uploadImage(req) {
|
||||
const {noteId} = req.query;
|
||||
const {file} = req;
|
||||
|
||||
const note = repository.getNote(noteId);
|
||||
const note = becca.getNote(noteId);
|
||||
|
||||
if (!note) {
|
||||
return [404, `Note ${noteId} doesn't exist.`];
|
||||
@@ -50,7 +50,7 @@ function updateImage(req) {
|
||||
const {noteId} = req.params;
|
||||
const {file} = req;
|
||||
|
||||
const note = repository.getNote(noteId);
|
||||
const note = becca.getNote(noteId);
|
||||
|
||||
if (!note) {
|
||||
return [404, `Note ${noteId} doesn't exist.`];
|
||||
|
||||
@@ -30,7 +30,7 @@ async function importToBranch(req) {
|
||||
return [400, "No file has been uploaded"];
|
||||
}
|
||||
|
||||
const parentNote = repository.getNote(parentNoteId);
|
||||
const parentNote = becca.getNote(parentNoteId);
|
||||
|
||||
if (!parentNote) {
|
||||
return [404, `Note ${parentNoteId} doesn't exist.`];
|
||||
|
||||
@@ -13,7 +13,7 @@ const becca = require("../../services/becca/becca.js");
|
||||
|
||||
function getNote(req) {
|
||||
const noteId = req.params.noteId;
|
||||
const note = repository.getNote(noteId);
|
||||
const note = becca.getNote(noteId);
|
||||
|
||||
if (!note) {
|
||||
return [404, "Note " + noteId + " has not been found."];
|
||||
@@ -67,7 +67,7 @@ function deleteNote(req) {
|
||||
// note how deleteId is separate from taskId - single taskId produces separate deleteId for each "top level" deleted note
|
||||
const deleteId = utils.randomString(10);
|
||||
|
||||
const note = repository.getNote(noteId);
|
||||
const note = becca.getNote(noteId);
|
||||
|
||||
const taskContext = TaskContext.getInstance(taskId, 'delete-notes');
|
||||
|
||||
@@ -81,7 +81,7 @@ function deleteNote(req) {
|
||||
}
|
||||
|
||||
function undeleteNote(req) {
|
||||
const note = repository.getNote(req.params.noteId);
|
||||
const note = becca.getNote(req.params.noteId);
|
||||
|
||||
const taskContext = TaskContext.getInstance(utils.randomString(10), 'undeleteNotes');
|
||||
|
||||
@@ -125,7 +125,7 @@ function setNoteTypeMime(req) {
|
||||
const type = req.params[1];
|
||||
const mime = req.params[2];
|
||||
|
||||
const note = repository.getNote(noteId);
|
||||
const note = becca.getNote(noteId);
|
||||
note.type = type;
|
||||
note.mime = mime;
|
||||
note.save();
|
||||
@@ -150,7 +150,7 @@ function getRelationMap(req) {
|
||||
|
||||
const questionMarks = noteIds.map(noteId => '?').join(',');
|
||||
|
||||
const relationMapNote = repository.getNote(relationMapNoteId);
|
||||
const relationMapNote = becca.getNote(relationMapNoteId);
|
||||
|
||||
const displayRelationsVal = relationMapNote.getLabelValue('displayRelations');
|
||||
const displayRelations = !displayRelationsVal ? [] : displayRelationsVal
|
||||
@@ -191,7 +191,7 @@ function changeTitle(req) {
|
||||
const noteId = req.params.noteId;
|
||||
const title = req.body.title;
|
||||
|
||||
const note = repository.getNote(noteId);
|
||||
const note = becca.getNote(noteId);
|
||||
|
||||
if (!note) {
|
||||
return [404, `Note ${noteId} has not been found`];
|
||||
@@ -246,7 +246,7 @@ function getDeleteNotesPreview(req) {
|
||||
}
|
||||
|
||||
for (const branchId of branchIdsToDelete) {
|
||||
const branch = repository.getBranch(branchId);
|
||||
const branch = becca.getBranch(branchId);
|
||||
|
||||
if (!branch) {
|
||||
log.error(`Branch ${branchId} was not found and delete preview can't be calculated for this note.`);
|
||||
@@ -280,7 +280,7 @@ function uploadModifiedFile(req) {
|
||||
const noteId = req.params.noteId;
|
||||
const {filePath} = req.body;
|
||||
|
||||
const note = repository.getNote(noteId);
|
||||
const note = becca.getNote(noteId);
|
||||
|
||||
if (!note) {
|
||||
return [404, `Note ${noteId} has not been found`];
|
||||
|
||||
@@ -30,7 +30,7 @@ async function exec(req) {
|
||||
}
|
||||
|
||||
async function run(req) {
|
||||
const note = repository.getNote(req.params.noteId);
|
||||
const note = becca.getNote(req.params.noteId);
|
||||
|
||||
const result = await scriptService.executeNote(note, { originEntity: note });
|
||||
|
||||
@@ -78,7 +78,7 @@ function getWidgetBundles() {
|
||||
|
||||
function getRelationBundles(req) {
|
||||
const noteId = req.params.noteId;
|
||||
const note = repository.getNote(noteId);
|
||||
const note = becca.getNote(noteId);
|
||||
const relationName = req.params.relationName;
|
||||
|
||||
const attributes = note.getAttributes();
|
||||
@@ -89,7 +89,7 @@ function getRelationBundles(req) {
|
||||
const bundles = [];
|
||||
|
||||
for (const noteId of uniqueNoteIds) {
|
||||
const note = repository.getNote(noteId);
|
||||
const note = becca.getNote(noteId);
|
||||
|
||||
if (!note.isJavaScript() || note.getScriptEnv() !== 'frontend') {
|
||||
continue;
|
||||
@@ -106,7 +106,7 @@ function getRelationBundles(req) {
|
||||
}
|
||||
|
||||
function getBundle(req) {
|
||||
const note = repository.getNote(req.params.noteId);
|
||||
const note = becca.getNote(req.params.noteId);
|
||||
|
||||
return scriptService.getScriptBundleForFrontend(note);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ async function searchFromNoteInt(note) {
|
||||
}
|
||||
|
||||
async function searchFromNote(req) {
|
||||
const note = repository.getNote(req.params.noteId);
|
||||
const note = becca.getNote(req.params.noteId);
|
||||
|
||||
if (!note) {
|
||||
return [404, `Note ${req.params.noteId} has not been found.`];
|
||||
@@ -130,7 +130,7 @@ function getActions(note) {
|
||||
}
|
||||
|
||||
async function searchAndExecute(req) {
|
||||
const note = repository.getNote(req.params.noteId);
|
||||
const note = becca.getNote(req.params.noteId);
|
||||
|
||||
if (!note) {
|
||||
return [404, `Note ${req.params.noteId} has not been found.`];
|
||||
@@ -150,7 +150,7 @@ async function searchAndExecute(req) {
|
||||
const actions = getActions(note);
|
||||
|
||||
for (const resultNoteId of searchResultNoteIds) {
|
||||
const resultNote = repository.getNote(resultNoteId);
|
||||
const resultNote = becca.getNote(resultNoteId);
|
||||
|
||||
if (!resultNote || resultNote.isDeleted) {
|
||||
continue;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
const similarityService = require('../../services/becca/similarity.js');
|
||||
const repository = require('../../services/repository');
|
||||
const becca = require("../../services/becca/becca.js");
|
||||
|
||||
async function getSimilarNotes(req) {
|
||||
const noteId = req.params.noteId;
|
||||
|
||||
const note = repository.getNote(noteId);
|
||||
const note = becca.getNote(noteId);
|
||||
|
||||
if (!note) {
|
||||
return [404, `Note ${noteId} not found.`];
|
||||
|
||||
@@ -18,7 +18,7 @@ function getSchema() {
|
||||
}
|
||||
|
||||
function execute(req) {
|
||||
const note = repository.getNote(req.params.noteId);
|
||||
const note = becca.getNote(req.params.noteId);
|
||||
|
||||
if (!note) {
|
||||
return [404, `Note ${req.params.noteId} was not found.`];
|
||||
|
||||
Reference in New Issue
Block a user