Skip to content

Build your personal knowledge base with Trilium Notes

gif support

azivner20b1357be6b6
diff --git a/migrations/0065__notes_image.sql b/migrations/0065__notes_image.sql
index 0202b85972..659006fa01 100644
--- a/migrations/0065__notes_image.sql
+++ b/migrations/0065__notes_image.sql
@@ -23,4 +23,5 @@ CREATE TABLE notes_image
);
CREATE INDEX notes_image_note_id_index ON notes_image (note_id);
+CREATE INDEX notes_image_image_id_index ON notes_image (image_id);
CREATE INDEX notes_image_note_id_image_id_index ON notes_image (note_id, image_id);
\ No newline at end of file
diff --git a/routes/api/image.js b/routes/api/image.js
index c51bacd18c..e7e61680b4 100644
--- a/routes/api/image.js
+++ b/routes/api/image.js
@@ -10,6 +10,7 @@ const multer = require('multer')();
const imagemin = require('imagemin');
const imageminMozJpeg = require('imagemin-mozjpeg');
const imageminPngQuant = require('imagemin-pngquant');
+const imageminGifLossy = require('imagemin-giflossy');
const jimp = require('jimp');
const imageType = require('image-type');
const sanitizeFilename = require('sanitize-filename');
@@ -34,11 +35,11 @@ router.post('', auth.checkApiAuth, multer.single('upload'), async (req, res, nex
const note = await sql.getFirst("SELECT * FROM notes WHERE note_id = ?", [noteId]);
if (!note) {
- return req.status(404).send(`Note ${noteId} doesn't exist.`);
+ return res.status(404).send(`Note ${noteId} doesn't exist.`);
}
- if (!["image/png", "image/jpeg"].includes(file.mimetype)) {
- return req.send("Unknown image type: " + file.mimetype);
+ if (!["image/png", "image/jpeg", "image/gif"].includes(file.mimetype)) {
+ return res.status(400).send("Unknown image type: " + file.mimetype);
}
const now = utils.nowDate();
@@ -47,7 +48,6 @@ router.post('', auth.checkApiAuth, multer.single('upload'), async (req, res, nex
const optimizedImage = await optimize(resizedImage);
const imageFormat = imageType(optimizedImage);
- console.log(imageFormat);
const fileNameWithouExtension = file.originalname.replace(/\.[^/.]+$/, "");
const fileName = sanitizeFilename(fileNameWithouExtension + "." + imageFormat.ext);
@@ -129,6 +129,10 @@ async function optimize(buffer) {
}),
imageminPngQuant({
quality: "0-70"
+ }),
+ imageminGifLossy({
+ lossy: 80,
+ optimize: '3' // needs to be string
})
]
});
diff --git a/services/consistency_checks.js b/services/consistency_checks.js
index 018a628ed8..c02b3352be 100644
--- a/services/consistency_checks.js
+++ b/services/consistency_checks.js
@@ -177,6 +177,16 @@ async function runAllChecks() {
COUNT(*) > 1`,
"Duplicate undeleted parent note <-> note relationship - parent note ID > note ID", errorList);
+ await runCheck(`
+ SELECT
+ images.image_id
+ FROM
+ images
+ LEFT JOIN notes_image ON notes_image.image_id = images.image_id
+ WHERE
+ notes_image.note_image_id IS NULL`,
+ "Image with no note relation", errorList);
+
await runSyncRowChecks("notes", "note_id", errorList);
await runSyncRowChecks("notes_history", "note_history_id", errorList);
await runSyncRowChecks("notes_tree", "note_tree_id", errorList);