mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
image upload fixes + some API changes
This commit is contained in:
parent
9e96272eb3
commit
0f42c396f3
2
src/public/javascripts/services/bootstrap.js
vendored
2
src/public/javascripts/services/bootstrap.js
vendored
@ -35,6 +35,8 @@ import libraryLoader from "./library_loader.js";
|
|||||||
window.glob.getCurrentNode = treeService.getCurrentNode;
|
window.glob.getCurrentNode = treeService.getCurrentNode;
|
||||||
window.glob.getHeaders = server.getHeaders;
|
window.glob.getHeaders = server.getHeaders;
|
||||||
window.glob.showAddLinkDialog = addLinkDialog.showDialog;
|
window.glob.showAddLinkDialog = addLinkDialog.showDialog;
|
||||||
|
// this is required by CKEditor when uploading images
|
||||||
|
window.glob.noteChanged = noteDetailService.noteChanged;
|
||||||
|
|
||||||
// required for ESLint plugin
|
// required for ESLint plugin
|
||||||
window.glob.getCurrentNote = noteDetailService.getCurrentNote;
|
window.glob.getCurrentNote = noteDetailService.getCurrentNote;
|
||||||
|
2
src/public/libraries/ckeditor/ckeditor.js
vendored
2
src/public/libraries/ckeditor/ckeditor.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -2,11 +2,13 @@
|
|||||||
|
|
||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
const syncTable = require('./sync_table');
|
const syncTable = require('./sync_table');
|
||||||
const tree = require('./tree');
|
const treeService = require('./tree');
|
||||||
|
const noteService = require('./notes');
|
||||||
|
const repository = require('./repository');
|
||||||
const Branch = require('../entities/branch');
|
const Branch = require('../entities/branch');
|
||||||
|
|
||||||
async function cloneNoteToParent(noteId, parentNoteId, prefix) {
|
async function cloneNoteToParent(noteId, parentNoteId, prefix) {
|
||||||
const validationResult = await tree.validateParentChild(parentNoteId, noteId);
|
const validationResult = await treeService.validateParentChild(parentNoteId, noteId);
|
||||||
|
|
||||||
if (!validationResult.success) {
|
if (!validationResult.success) {
|
||||||
return validationResult;
|
return validationResult;
|
||||||
@ -24,10 +26,24 @@ async function cloneNoteToParent(noteId, parentNoteId, prefix) {
|
|||||||
return { success: true };
|
return { success: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function cloneNoteAfter(noteId, afterBranchId) {
|
// this is identical to cloneNoteToParent except for the intention - if cloned note is already in parent,
|
||||||
const afterNote = await tree.getBranch(afterBranchId);
|
// then this is successful result
|
||||||
|
async function ensureNoteIsPresentInParent(noteId, parentNoteId, prefix) {
|
||||||
|
await cloneNoteToParent(noteId, parentNoteId, prefix);
|
||||||
|
}
|
||||||
|
|
||||||
const validationResult = await tree.validateParentChild(afterNote.parentNoteId, noteId);
|
async function ensureNoteIsAbsentFromParent(noteId, parentNoteId) {
|
||||||
|
const branch = await repository.getEntity(`SELECT * FROM branches WHERE noteId = ? AND parentNoteId = ? AND isDeleted = 0`, [noteId, parentNoteId]);
|
||||||
|
|
||||||
|
if (branch) {
|
||||||
|
await noteService.deleteNote(branch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function cloneNoteAfter(noteId, afterBranchId) {
|
||||||
|
const afterNote = await treeService.getBranch(afterBranchId);
|
||||||
|
|
||||||
|
const validationResult = await treeService.validateParentChild(afterNote.parentNoteId, noteId);
|
||||||
|
|
||||||
if (!validationResult.result) {
|
if (!validationResult.result) {
|
||||||
return validationResult;
|
return validationResult;
|
||||||
@ -52,5 +68,7 @@ async function cloneNoteAfter(noteId, afterBranchId) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
cloneNoteToParent,
|
cloneNoteToParent,
|
||||||
|
ensureNoteIsPresentInParent,
|
||||||
|
ensureNoteIsAbsentFromParent,
|
||||||
cloneNoteAfter
|
cloneNoteAfter
|
||||||
};
|
};
|
@ -62,7 +62,8 @@ async function updateEntity(entity) {
|
|||||||
delete clone.isOwned;
|
delete clone.isOwned;
|
||||||
|
|
||||||
for (const key in clone) {
|
for (const key in clone) {
|
||||||
if (clone[key] !== null && typeof clone[key] === 'object') {
|
// !isBuffer is for images and attachments
|
||||||
|
if (clone[key] !== null && typeof clone[key] === 'object' && !Buffer.isBuffer(clone[key])) {
|
||||||
clone[key] = JSON.stringify(clone[key]);
|
clone[key] = JSON.stringify(clone[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ const treeService = require('./tree');
|
|||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
const repository = require('./repository');
|
const repository = require('./repository');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
const cloningService = require('./cloning');
|
||||||
|
const messagingService = require('./messaging');
|
||||||
|
|
||||||
function ScriptContext(startNote, allNotes, originEntity = null) {
|
function ScriptContext(startNote, allNotes, originEntity = null) {
|
||||||
this.modules = {};
|
this.modules = {};
|
||||||
@ -54,6 +56,9 @@ function ScriptApi(startNote, currentNote, originEntity) {
|
|||||||
this.getNotesWithLabel = attributeService.getNotesWithLabel;
|
this.getNotesWithLabel = attributeService.getNotesWithLabel;
|
||||||
this.getNoteWithLabel = attributeService.getNoteWithLabel;
|
this.getNoteWithLabel = attributeService.getNoteWithLabel;
|
||||||
|
|
||||||
|
this.ensureNoteIsPresentInParent = cloningService.ensureNoteIsPresentInParent;
|
||||||
|
this.ensureNoteIsAbsentFromParent = cloningService.ensureNoteIsAbsentFromParent;
|
||||||
|
|
||||||
this.createNote = noteService.createNote;
|
this.createNote = noteService.createNote;
|
||||||
|
|
||||||
this.log = message => log.info(`Script ${currentNote.noteId}: ${message}`);
|
this.log = message => log.info(`Script ${currentNote.noteId}: ${message}`);
|
||||||
@ -64,6 +69,8 @@ function ScriptApi(startNote, currentNote, originEntity) {
|
|||||||
this.sortNotesAlphabetically = treeService.sortNotesAlphabetically;
|
this.sortNotesAlphabetically = treeService.sortNotesAlphabetically;
|
||||||
|
|
||||||
this.transactional = sql.transactional;
|
this.transactional = sql.transactional;
|
||||||
|
|
||||||
|
this.refreshTree = () => messagingService.sendMessageToAllClients({ type: 'refresh-tree' });
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ScriptContext;
|
module.exports = ScriptContext;
|
Loading…
x
Reference in New Issue
Block a user