mirror of
https://github.com/zadam/trilium.git
synced 2025-11-17 10:40:41 +01:00
smaller refactorings continued
This commit is contained in:
@@ -21,14 +21,11 @@ async function cloneNoteToParent(req) {
|
||||
const newNotePos = maxNotePos === null ? 0 : maxNotePos + 1;
|
||||
|
||||
const branch = new Branch({
|
||||
branchId: utils.newBranchId(),
|
||||
noteId: childNoteId,
|
||||
parentNoteId: parentNoteId,
|
||||
prefix: prefix,
|
||||
notePosition: newNotePos,
|
||||
isExpanded: 0,
|
||||
dateModified: utils.nowDate(),
|
||||
isDeleted: 0
|
||||
isExpanded: 0
|
||||
});
|
||||
|
||||
await branch.save();
|
||||
@@ -58,13 +55,10 @@ async function cloneNoteAfter(req) {
|
||||
await sync_table.addNoteReorderingSync(afterNote.parentNoteId);
|
||||
|
||||
const branch = new Branch({
|
||||
branchId: utils.newBranchId(),
|
||||
noteId: noteId,
|
||||
parentNoteId: afterNote.parentNoteId,
|
||||
notePosition: afterNote.notePosition + 1,
|
||||
isExpanded: 0,
|
||||
dateModified: utils.nowDate(),
|
||||
isDeleted: 0
|
||||
isExpanded: 0
|
||||
});
|
||||
|
||||
await branch.save();
|
||||
|
||||
@@ -29,7 +29,6 @@ async function updateNoteLabels(req) {
|
||||
}
|
||||
|
||||
labelEntity = new Label();
|
||||
labelEntity.labelId = utils.newLabelId();
|
||||
labelEntity.noteId = noteId;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
const sql = require('../../services/sql');
|
||||
const notes = require('../../services/notes');
|
||||
const utils = require('../../services/utils');
|
||||
const tree = require('../../services/tree');
|
||||
const sync_table = require('../../services/sync_table');
|
||||
const repository = require('../../services/repository');
|
||||
|
||||
async function getNote(req) {
|
||||
@@ -57,14 +54,12 @@ async function protectBranch(req) {
|
||||
}
|
||||
|
||||
async function setNoteTypeMime(req) {
|
||||
const noteId = req.params[0];
|
||||
const type = req.params[1];
|
||||
const mime = req.params[2];
|
||||
const [noteId, type, mime] = req.params;
|
||||
|
||||
await sql.execute("UPDATE notes SET type = ?, mime = ?, dateModified = ? WHERE noteId = ?",
|
||||
[type, mime, utils.nowDate(), noteId]);
|
||||
|
||||
await sync_table.addNoteSync(noteId);
|
||||
const note = await repository.getNote(noteId);
|
||||
note.type = type;
|
||||
note.mime = mime;
|
||||
await note.save();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -7,7 +7,7 @@ const sql = require('../../services/sql');
|
||||
const notes = require('../../services/notes');
|
||||
const password_encryption = require('../../services/password_encryption');
|
||||
const options = require('../../services/options');
|
||||
const sync_table = require('../../services/sync_table');
|
||||
const ApiToken = require('../../entities/api_token');
|
||||
|
||||
async function login(req) {
|
||||
const username = req.body.username;
|
||||
@@ -20,21 +20,11 @@ async function login(req) {
|
||||
return [401, "Incorrect username/password"];
|
||||
}
|
||||
|
||||
const token = utils.randomSecureToken();
|
||||
|
||||
const apiTokenId = utils.newApiTokenId();
|
||||
|
||||
await sql.insert("api_tokens", {
|
||||
apiTokenId: apiTokenId,
|
||||
token: token,
|
||||
dateCreated: utils.nowDate(),
|
||||
isDeleted: false
|
||||
});
|
||||
|
||||
await sync_table.addApiTokenSync(apiTokenId);
|
||||
const apiToken = new ApiToken({ token: utils.randomSecureToken() });
|
||||
await apiToken.save();
|
||||
|
||||
return {
|
||||
token: token
|
||||
token: apiToken.token
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ async function forceNoteSync(req) {
|
||||
}
|
||||
|
||||
for (const noteRevisionId of await sql.getColumn("SELECT noteRevisionId FROM note_revisions WHERE noteId = ?", [noteId])) {
|
||||
await sync_table.addNoteRevisionsSync(noteRevisionId);
|
||||
await sync_table.addNoteRevisionSync(noteRevisionId);
|
||||
}
|
||||
|
||||
log.info("Forcing note sync for " + noteId);
|
||||
|
||||
Reference in New Issue
Block a user