diff --git a/Dockerfile b/Dockerfile index cb47e0c7c..897d3de64 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +# !!! Don't try to build this Dockerfile directly, run it through bin/build-docker.sh script !!! FROM node:16.14.0-alpine # Create app directory diff --git a/bin/copy-trilium.sh b/bin/copy-trilium.sh index d9831c683..31dbfb13d 100755 --- a/bin/copy-trilium.sh +++ b/bin/copy-trilium.sh @@ -47,8 +47,11 @@ find $DIR/node_modules -name demo -exec rm -rf {} \; find $DIR/libraries -name "*.map" -type f -delete +cp $DIR/src/public/app/share.js $DIR/src/public/app-dist/ + rm -rf $DIR/src/public/app sed -i -e 's/app\/desktop.js/app-dist\/desktop.js/g' $DIR/src/views/desktop.ejs sed -i -e 's/app\/mobile.js/app-dist\/mobile.js/g' $DIR/src/views/mobile.ejs sed -i -e 's/app\/setup.js/app-dist\/setup.js/g' $DIR/src/views/setup.ejs +sed -i -e 's/app\/share.js/app-dist\/share.js/g' $DIR/src/views/share/*.ejs diff --git a/package.json b/package.json index 94c23f673..d247b9f87 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "electron-dl": "3.3.0", "electron-find": "1.0.7", "electron-window-state": "5.0.3", - "@electron/remote": "2.0.4", + "@electron/remote": "2.0.8", "express": "4.17.2", "express-partial-content": "1.0.2", "express-rate-limit": "6.2.1", @@ -82,8 +82,8 @@ }, "devDependencies": { "cross-env": "7.0.3", - "electron": "16.0.8", - "electron-builder": "22.14.13", + "electron": "16.1.0", + "electron-builder": "22.14.5", "electron-packager": "15.4.0", "electron-rebuild": "3.2.7", "esm": "3.2.25", diff --git a/src/app.js b/src/app.js index 6ba7c1b78..b530ca7e4 100644 --- a/src/app.js +++ b/src/app.js @@ -25,6 +25,7 @@ app.use(helmet({ app.use(express.text({limit: '500mb'})); app.use(express.json({limit: '500mb'})); +app.use(express.raw({limit: '500mb'})); app.use(express.urlencoded({extended: false})); app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public'))); diff --git a/src/becca/entities/note.js b/src/becca/entities/note.js index 7d0c57c72..43e1c93f1 100644 --- a/src/becca/entities/note.js +++ b/src/becca/entities/note.js @@ -1127,6 +1127,7 @@ class Note extends AbstractEntity { if (this.isProtected && !this.isDecrypted && protectedSessionService.isProtectedSessionAvailable()) { try { this.title = protectedSessionService.decryptString(this.title); + this.flatTextCache = null; this.isDecrypted = true; } diff --git a/src/public/robots.txt b/src/public/robots.txt index 1f53798bb..7ea32fccc 100644 --- a/src/public/robots.txt +++ b/src/public/robots.txt @@ -1,2 +1,3 @@ User-agent: * +Allow: /share/ Disallow: / diff --git a/src/public/stylesheets/ckeditor-theme.css b/src/public/stylesheets/ckeditor-theme.css index 8ef29a790..54608015c 100644 --- a/src/public/stylesheets/ckeditor-theme.css +++ b/src/public/stylesheets/ckeditor-theme.css @@ -93,6 +93,8 @@ body { --ck-color-labeled-field-label-background: var(--accented-background-color); + --ck-color-editable-blur-selection: var(--accented-background-color); + /* todo lists */ --ck-color-todo-list-checkmark-border: var(--main-border-color); diff --git a/src/public/stylesheets/share.css b/src/public/stylesheets/share.css index 1031eaa9f..718f8594c 100644 --- a/src/public/stylesheets/share.css +++ b/src/public/stylesheets/share.css @@ -1,5 +1,6 @@ body { font-family: 'Lucida Grande', 'Lucida Sans Unicode', arial, sans-serif; + line-height: 1.5; } #layout { diff --git a/src/routes/api/clipper.js b/src/routes/api/clipper.js index 27c876b1e..d777b9bb9 100644 --- a/src/routes/api/clipper.js +++ b/src/routes/api/clipper.js @@ -138,7 +138,7 @@ function processContent(images, note, content) { value: imageNote.noteId }).save(); - console.log(`Replacing ${imageId} with ${url}`); + log.info(`Replacing ${imageId} with ${url} in note ${note.noteId}`); rewrittenContent = utils.replaceAll(rewrittenContent, imageId, url); } diff --git a/src/services/attributes.js b/src/services/attributes.js index 5fcc121bd..3ddd41223 100644 --- a/src/services/attributes.js +++ b/src/services/attributes.js @@ -20,7 +20,7 @@ function getNotesWithLabel(name, value) { // TODO: should be in search service /** @returns {Note|null} */ -function getNoteWithLabel(name, value) { +function getNoteWithLabel(name, value = undefined) { // optimized version (~20 times faster) without using normal search, useful for e.g. finding date notes const attrs = becca.findAttributes('label', name); diff --git a/src/services/image.js b/src/services/image.js index 9457d1aa4..4c64e8ee5 100644 --- a/src/services/image.js +++ b/src/services/image.js @@ -17,8 +17,7 @@ async function processImage(uploadBuffer, originalName, shrinkImageSwitch) { const compressImages = optionService.getOptionBool("compressImages"); const origImageFormat = getImageType(uploadBuffer); - if (origImageFormat && ["webp", "svg", "gif"].includes(origImageFormat.ext)) { - // JIMP does not support webp at the moment: https://github.com/oliver-moran/jimp/issues/144 + if (!origImageFormat || !["jpg", "png"].includes(origImageFormat.ext)) { shrinkImageSwitch = false; } else if (isAnimated(uploadBuffer)) { @@ -26,9 +25,18 @@ async function processImage(uploadBuffer, originalName, shrinkImageSwitch) { shrinkImageSwitch = false; } - const finalImageBuffer = (compressImages && shrinkImageSwitch) ? await shrinkImage(uploadBuffer, originalName) : uploadBuffer; + let finalImageBuffer; + let imageFormat; - const imageFormat = getImageType(finalImageBuffer); + if (compressImages && shrinkImageSwitch) { + finalImageBuffer = await shrinkImage(uploadBuffer, originalName); + imageFormat = getImageType(finalImageBuffer); + } else { + finalImageBuffer = uploadBuffer; + imageFormat = origImageFormat || { + ext: 'dat' + }; + } return { buffer: finalImageBuffer, @@ -43,7 +51,9 @@ function getImageType(buffer) { } } else { - return imageType(buffer) || "jpg"; // optimistic JPG default + return imageType(buffer) || { + ext: "jpg" + }; // optimistic JPG default } } @@ -75,7 +85,7 @@ function updateImage(noteId, uploadBuffer, originalName) { } function saveImage(parentNoteId, uploadBuffer, originalName, shrinkImageSwitch, trimFilename = false) { - log.info(`Saving image ${originalName}`); + log.info(`Saving image ${originalName} into parent ${parentNoteId}`); if (trimFilename && originalName.length > 40) { // https://github.com/zadam/trilium/issues/2307 diff --git a/test-etapi/put-note-content-binary.http b/test-etapi/put-note-content-binary.http new file mode 100644 index 000000000..545b3c111 --- /dev/null +++ b/test-etapi/put-note-content-binary.http @@ -0,0 +1,25 @@ +POST {{triliumHost}}/etapi/create-note +Authorization: {{authToken}} +Content-Type: application/json + +{ + "parentNoteId": "root", + "title": "Hello", + "type": "image", + "mime": "image/png", + "content": "" +} + +> {% client.global.set("createdNoteId", response.body.note.noteId); %} + +### + +PUT {{triliumHost}}/etapi/notes/{{createdNoteId}}/content +Authorization: {{authToken}} +Content-Type: application/octet-stream +Content-Transfer-Encoding: binary + +< ../images/icon-color.png + +> {% client.assert(response.status === 204); %} + diff --git a/test-etapi/put-note-content.http b/test-etapi/put-note-content.http index 10b7f1d21..66797c0dc 100644 --- a/test-etapi/put-note-content.http +++ b/test-etapi/put-note-content.http @@ -20,6 +20,8 @@ Content-Type: text/plain Changed content +> {% client.assert(response.status === 200); %} + ### GET {{triliumHost}}/etapi/notes/{{createdNoteId}}/content