image upload fixes + some API changes

This commit is contained in:
azivner 2018-08-11 19:45:55 +02:00
parent 9e96272eb3
commit 0f42c396f3
6 changed files with 36 additions and 8 deletions

View File

@ -35,6 +35,8 @@ import libraryLoader from "./library_loader.js";
window.glob.getCurrentNode = treeService.getCurrentNode;
window.glob.getHeaders = server.getHeaders;
window.glob.showAddLinkDialog = addLinkDialog.showDialog;
// this is required by CKEditor when uploading images
window.glob.noteChanged = noteDetailService.noteChanged;
// required for ESLint plugin
window.glob.getCurrentNote = noteDetailService.getCurrentNote;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -2,11 +2,13 @@
const sql = require('./sql');
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');
async function cloneNoteToParent(noteId, parentNoteId, prefix) {
const validationResult = await tree.validateParentChild(parentNoteId, noteId);
const validationResult = await treeService.validateParentChild(parentNoteId, noteId);
if (!validationResult.success) {
return validationResult;
@ -24,10 +26,24 @@ async function cloneNoteToParent(noteId, parentNoteId, prefix) {
return { success: true };
}
async function cloneNoteAfter(noteId, afterBranchId) {
const afterNote = await tree.getBranch(afterBranchId);
// this is identical to cloneNoteToParent except for the intention - if cloned note is already in parent,
// 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) {
return validationResult;
@ -52,5 +68,7 @@ async function cloneNoteAfter(noteId, afterBranchId) {
module.exports = {
cloneNoteToParent,
ensureNoteIsPresentInParent,
ensureNoteIsAbsentFromParent,
cloneNoteAfter
};

View File

@ -62,7 +62,8 @@ async function updateEntity(entity) {
delete clone.isOwned;
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]);
}
}

View File

@ -9,6 +9,8 @@ const treeService = require('./tree');
const config = require('./config');
const repository = require('./repository');
const axios = require('axios');
const cloningService = require('./cloning');
const messagingService = require('./messaging');
function ScriptContext(startNote, allNotes, originEntity = null) {
this.modules = {};
@ -54,6 +56,9 @@ function ScriptApi(startNote, currentNote, originEntity) {
this.getNotesWithLabel = attributeService.getNotesWithLabel;
this.getNoteWithLabel = attributeService.getNoteWithLabel;
this.ensureNoteIsPresentInParent = cloningService.ensureNoteIsPresentInParent;
this.ensureNoteIsAbsentFromParent = cloningService.ensureNoteIsAbsentFromParent;
this.createNote = noteService.createNote;
this.log = message => log.info(`Script ${currentNote.noteId}: ${message}`);
@ -64,6 +69,8 @@ function ScriptApi(startNote, currentNote, originEntity) {
this.sortNotesAlphabetically = treeService.sortNotesAlphabetically;
this.transactional = sql.transactional;
this.refreshTree = () => messagingService.sendMessageToAllClients({ type: 'refresh-tree' });
}
module.exports = ScriptContext;