mirror of
https://github.com/zadam/trilium.git
synced 2025-01-01 12:52:17 +08:00
gif support
This commit is contained in:
parent
d9f2bb37e7
commit
20b1357be6
3 changed files with 19 additions and 4 deletions
|
@ -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);
|
|
@ -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
|
||||
})
|
||||
]
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue