save note in clipper

This commit is contained in:
zadam 2019-07-06 16:48:06 +02:00
parent 093dfb4a39
commit 976684a3a8
5 changed files with 39 additions and 41 deletions

View File

@ -1,4 +1,4 @@
FROM node:12.4.0-alpine FROM node:12.6.0-alpine
# Create app directory # Create app directory
WORKDIR /usr/src/app WORKDIR /usr/src/app

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
PKG_DIR=dist/trilium-linux-x64-server PKG_DIR=dist/trilium-linux-x64-server
NODE_VERSION=12.4.0 NODE_VERSION=12.6.0
rm -r $PKG_DIR rm -r $PKG_DIR
mkdir $PKG_DIR mkdir $PKG_DIR

6
package-lock.json generated
View File

@ -5287,9 +5287,9 @@
} }
}, },
"file-type": { "file-type": {
"version": "12.0.0", "version": "12.0.1",
"resolved": "https://registry.npmjs.org/file-type/-/file-type-12.0.0.tgz", "resolved": "https://registry.npmjs.org/file-type/-/file-type-12.0.1.tgz",
"integrity": "sha512-VV3aQAyoV/fHl0I9uU3/DGjItgh5nylAoJPHOXkZXHW4nFFrxJnHR2xdVqsqyw/9fqYy80m+tS+Rf77w0FTKqg==" "integrity": "sha512-YIs1E51cmqcmgF38ODjy0+M/l5DyfIIy3vngTOujQr/lXqkaSskfBniaZoZ1HVIpa5FTf5e7hCXS4TzxfNGMRQ=="
}, },
"filename-regex": { "filename-regex": {
"version": "2.0.1", "version": "2.0.1",

View File

@ -38,7 +38,7 @@
"electron-window-state": "5.0.3", "electron-window-state": "5.0.3",
"express": "4.17.1", "express": "4.17.1",
"express-session": "1.16.2", "express-session": "1.16.2",
"file-type": "12.0.0", "file-type": "12.0.1",
"fs-extra": "8.1.0", "fs-extra": "8.1.0",
"get-port": "5.0.0", "get-port": "5.0.0",
"helmet": "3.18.0", "helmet": "3.18.0",

View File

@ -10,48 +10,44 @@ const path = require('path');
const Link = require('../../entities/link'); const Link = require('../../entities/link');
async function createNote(req) { async function createNote(req) {
const {title, html, url, images} = req.body; const {title, content, url, images} = req.body;
const todayNote = await dateNoteService.getDateNote(dateUtils.localNowDate()); const todayNote = await dateNoteService.getDateNote(dateUtils.localNowDate());
const {note} = await noteService.createNote(todayNote.noteId, title, html, { const {note} = await noteService.createNote(todayNote.noteId, title, content);
attributes: [
{
type: 'label',
name: 'sourceUrl',
value: url
}
]
});
let rewrittenHtml = html; if (url) {
await note.setLabel('sourceUrl', url);
for (const {src, dataUrl, imageId} of images) {
const filename = path.basename(src);
if (!dataUrl.startsWith("data:image")) {
log.info("Image could not be recognized as data URL:", dataUrl.substr(0, Math.min(100, dataUrl.length)));
continue;
}
const buffer = Buffer.from(dataUrl.split(",")[1], 'base64');
const {note: imageNote, url} = await imageService.saveImage(buffer, filename, note.noteId, true);
await new Link({
noteId: note.noteId,
targetNoteId: imageNote.noteId,
type: 'image'
}).save();
console.log(`Replacing ${imageId} with ${url}`);
rewrittenHtml = rewrittenHtml.replace(imageId, url);
} }
console.log("Done", rewrittenHtml); let rewrittenContent = content;
await note.setContent(rewrittenHtml); if (images) {
for (const {src, dataUrl, imageId} of images) {
const filename = path.basename(src);
if (!dataUrl.startsWith("data:image")) {
log.info("Image could not be recognized as data URL:", dataUrl.substr(0, Math.min(100, dataUrl.length)));
continue;
}
const buffer = Buffer.from(dataUrl.split(",")[1], 'base64');
const {note: imageNote, url} = await imageService.saveImage(buffer, filename, note.noteId, true);
await new Link({
noteId: note.noteId,
targetNoteId: imageNote.noteId,
type: 'image'
}).save();
console.log(`Replacing ${imageId} with ${url}`);
rewrittenContent = rewrittenContent.replace(imageId, url);
}
}
await note.setContent(rewrittenContent);
return { return {
noteId: note.noteId noteId: note.noteId
@ -105,6 +101,8 @@ async function openNote(req) {
type: 'open-note', type: 'open-note',
noteId: req.params.noteId noteId: req.params.noteId
}); });
return {};
} }
async function ping(req, res) { async function ping(req, res) {