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:
@@ -5,7 +5,7 @@ const log = require('../../services/log');
|
||||
const attributeService = require('../../services/attributes');
|
||||
const repository = require('../../services/repository');
|
||||
const Attribute = require('../../entities/attribute');
|
||||
const becca = require("../../services/becca/becca.js");
|
||||
const becca = require("../../services/becca/becca");
|
||||
|
||||
function getEffectiveNoteAttributes(req) {
|
||||
const note = becca.getNote(req.params.noteId);
|
||||
|
||||
@@ -6,6 +6,7 @@ const repository = require('../../services/repository');
|
||||
const log = require('../../services/log');
|
||||
const utils = require('../../services/utils');
|
||||
const cls = require('../../services/cls');
|
||||
const becca = require("../../services/becca/becca");
|
||||
|
||||
function getAutocomplete(req) {
|
||||
const query = req.query.query.trim();
|
||||
@@ -41,7 +42,7 @@ function getRecentNotes(activeNoteId) {
|
||||
params.push('%' + hoistedNoteId + '%');
|
||||
}
|
||||
|
||||
const recentNotes = repository.getEntities(`
|
||||
const recentNotes = becca.getRecentNotesFromQuery(`
|
||||
SELECT
|
||||
recent_notes.*
|
||||
FROM
|
||||
|
||||
@@ -9,7 +9,7 @@ const fs = require('fs');
|
||||
const { Readable } = require('stream');
|
||||
const chokidar = require('chokidar');
|
||||
const ws = require('../../services/ws');
|
||||
const becca = require("../../services/becca/becca.js");
|
||||
const becca = require("../../services/becca/becca");
|
||||
|
||||
function updateFile(req) {
|
||||
const {noteId} = req.params;
|
||||
|
||||
@@ -7,10 +7,10 @@ const noteRevisionService = require('../../services/note_revisions');
|
||||
const utils = require('../../services/utils');
|
||||
const sql = require('../../services/sql');
|
||||
const path = require('path');
|
||||
const becca = require("../../services/becca/becca.js");
|
||||
const becca = require("../../services/becca/becca");
|
||||
|
||||
function getNoteRevisions(req) {
|
||||
return repository.getEntities(`
|
||||
return becca.getNoteRevisionsFromQuery(`
|
||||
SELECT note_revisions.*,
|
||||
LENGTH(note_revision_contents.content) AS contentLength
|
||||
FROM note_revisions
|
||||
@@ -107,7 +107,7 @@ function restoreNoteRevision(req) {
|
||||
}
|
||||
|
||||
function getEditedNotesOnDate(req) {
|
||||
const notes = repository.getEntities(`
|
||||
const noteIds = sql.getColumn(`
|
||||
SELECT notes.*
|
||||
FROM notes
|
||||
WHERE noteId IN (
|
||||
@@ -121,6 +121,8 @@ function getEditedNotesOnDate(req) {
|
||||
ORDER BY isDeleted
|
||||
LIMIT 50`, {date: req.params.date + '%'});
|
||||
|
||||
const notes = becca.getNotes(noteIds);
|
||||
|
||||
for (const note of notes) {
|
||||
const notePath = note.isDeleted ? null : beccaService.getNotePath(note.noteId);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ const log = require('../../services/log');
|
||||
const TaskContext = require('../../services/task_context');
|
||||
const fs = require('fs');
|
||||
const noteRevisionService = require("../../services/note_revisions.js");
|
||||
const becca = require("../../services/becca/becca.js");
|
||||
const becca = require("../../services/becca/becca");
|
||||
|
||||
function getNote(req) {
|
||||
const noteId = req.params.noteId;
|
||||
@@ -159,7 +159,8 @@ function getRelationMap(req) {
|
||||
|
||||
console.log("displayRelations", displayRelations);
|
||||
|
||||
const notes = repository.getEntities(`SELECT * FROM notes WHERE isDeleted = 0 AND noteId IN (${questionMarks})`, noteIds);
|
||||
const foundNoteIds = sql.getColumn(`SELECT noteId FROM notes WHERE isDeleted = 0 AND noteId IN (${questionMarks})`, noteIds);
|
||||
const notes = becca.getNotes(foundNoteIds);
|
||||
|
||||
for (const note of notes) {
|
||||
resp.noteTitles[note.noteId] = note.title;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
const RecentNote = require('../../entities/recent_note');
|
||||
const RecentNote = require('../../services/becca/entities/recent_note.js');
|
||||
const sql = require('../../services/sql');
|
||||
const dateUtils = require('../../services/date_utils');
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ const log = require('../../services/log');
|
||||
const scriptService = require('../../services/script');
|
||||
const searchService = require('../../services/search/services/search');
|
||||
const noteRevisionService = require("../../services/note_revisions.js");
|
||||
const {formatAttrForSearch} = require("../../services/attribute_formatter.js");
|
||||
|
||||
async function searchFromNoteInt(note) {
|
||||
let searchResultNoteIds;
|
||||
@@ -267,51 +268,6 @@ function getRelatedNotes(req) {
|
||||
};
|
||||
}
|
||||
|
||||
function formatAttrForSearch(attr, searchWithValue) {
|
||||
let searchStr = '';
|
||||
|
||||
if (attr.type === 'label') {
|
||||
searchStr += '#';
|
||||
}
|
||||
else if (attr.type === 'relation') {
|
||||
searchStr += '~';
|
||||
}
|
||||
else {
|
||||
throw new Error(`Unrecognized attribute type ${JSON.stringify(attr)}`);
|
||||
}
|
||||
|
||||
searchStr += attr.name;
|
||||
|
||||
if (searchWithValue && attr.value) {
|
||||
if (attr.type === 'relation') {
|
||||
searchStr += ".noteId";
|
||||
}
|
||||
|
||||
searchStr += '=';
|
||||
searchStr += formatValue(attr.value);
|
||||
}
|
||||
|
||||
return searchStr;
|
||||
}
|
||||
|
||||
function formatValue(val) {
|
||||
if (!/[^\w_-]/.test(val)) {
|
||||
return val;
|
||||
}
|
||||
else if (!val.includes('"')) {
|
||||
return '"' + val + '"';
|
||||
}
|
||||
else if (!val.includes("'")) {
|
||||
return "'" + val + "'";
|
||||
}
|
||||
else if (!val.includes("`")) {
|
||||
return "`" + val + "`";
|
||||
}
|
||||
else {
|
||||
return '"' + val.replace(/"/g, '\\"') + '"';
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
searchFromNote,
|
||||
searchAndExecute,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
const similarityService = require('../../services/becca/similarity.js');
|
||||
const becca = require("../../services/becca/becca.js");
|
||||
const becca = require("../../services/becca/becca");
|
||||
|
||||
async function getSimilarNotes(req) {
|
||||
const noteId = req.params.noteId;
|
||||
|
||||
@@ -3,13 +3,17 @@ const log = require('../services/log');
|
||||
const fileUploadService = require('./api/files.js');
|
||||
const scriptService = require('../services/script');
|
||||
const cls = require('../services/cls');
|
||||
const sql = require("../services/sql");
|
||||
const becca = require("../services/becca/becca");
|
||||
|
||||
async function handleRequest(req, res) {
|
||||
// express puts content after first slash into 0 index element
|
||||
|
||||
const path = req.params.path + req.params[0];
|
||||
|
||||
const attrs = repository.getEntities("SELECT * FROM attributes WHERE isDeleted = 0 AND type = 'label' AND name IN ('customRequestHandler', 'customResourceProvider')");
|
||||
const attributeIds = sql.getColumn("SELECT attributeId FROM attributes WHERE isDeleted = 0 AND type = 'label' AND name IN ('customRequestHandler', 'customResourceProvider')");
|
||||
|
||||
const attrs = attributeIds.map(attrId => becca.getAttribute(attrId));
|
||||
|
||||
for (const attr of attrs) {
|
||||
if (!attr.value.trim()) {
|
||||
|
||||
Reference in New Issue
Block a user