mirror of
https://github.com/zadam/trilium.git
synced 2025-06-05 17:38:47 +02:00
basic webp support
This commit is contained in:
parent
f45e25172b
commit
5d213eea7e
@ -34,7 +34,7 @@ async function uploadImage(req) {
|
||||
return [404, `Note ${noteId} doesn't exist.`];
|
||||
}
|
||||
|
||||
if (!["image/png", "image/jpeg", "image/gif"].includes(file.mimetype)) {
|
||||
if (!["image/png", "image/jpeg", "image/gif", "image/webp"].includes(file.mimetype)) {
|
||||
return [400, "Unknown image type: " + file.mimetype];
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,13 @@ const imageType = require('image-type');
|
||||
const sanitizeFilename = require('sanitize-filename');
|
||||
|
||||
async function saveImage(buffer, originalName, parentNoteId, shrinkImageSwitch) {
|
||||
const origImageFormat = imageType(buffer);
|
||||
|
||||
if (origImageFormat.ext === "webp") {
|
||||
// JIMP does not support webp at the moment: https://github.com/oliver-moran/jimp/issues/144
|
||||
shrinkImageSwitch = false;
|
||||
}
|
||||
|
||||
const finalImageBuffer = shrinkImageSwitch ? await shrinkImage(buffer, originalName) : buffer;
|
||||
|
||||
const imageFormat = imageType(finalImageBuffer);
|
||||
|
@ -251,7 +251,7 @@ async function importEnex(importContext, file, parentNote) {
|
||||
noteContent = noteContent.replace(mediaRegex, resourceLink);
|
||||
};
|
||||
|
||||
if (["image/jpeg", "image/png", "image/gif"].includes(resource.mime)) {
|
||||
if (["image/jpeg", "image/png", "image/gif", "image/webp"].includes(resource.mime)) {
|
||||
try {
|
||||
const originalName = "image." + resource.mime.substr(6);
|
||||
|
||||
|
@ -100,7 +100,7 @@ async function importSingleFile(importContext, file, parentNote) {
|
||||
return await importCodeNote(importContext, file, parentNote);
|
||||
}
|
||||
|
||||
if (["image/jpeg", "image/gif", "image/png"].includes(mime)) {
|
||||
if (["image/jpeg", "image/gif", "image/png", "image/webp"].includes(mime)) {
|
||||
return await importImage(file, parentNote, importContext);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user