mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
pasted images should have trimmed names if too long (too often it's just garbage), closes #2307
This commit is contained in:
parent
b02a5b872a
commit
e57dee2f14
@ -38,7 +38,7 @@ function uploadImage(req) {
|
|||||||
return [400, "Unknown image type: " + file.mimetype];
|
return [400, "Unknown image type: " + file.mimetype];
|
||||||
}
|
}
|
||||||
|
|
||||||
const {url} = imageService.saveImage(noteId, file.buffer, file.originalname, true);
|
const {url} = imageService.saveImage(noteId, file.buffer, file.originalname, true, true);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
uploaded: true,
|
uploaded: true,
|
||||||
|
@ -73,11 +73,15 @@ function updateImage(noteId, uploadBuffer, originalName) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveImage(parentNoteId, uploadBuffer, originalName, shrinkImageSwitch) {
|
function saveImage(parentNoteId, uploadBuffer, originalName, shrinkImageSwitch, trimFilename = false) {
|
||||||
log.info(`Saving image ${originalName}`);
|
log.info(`Saving image ${originalName}`);
|
||||||
|
|
||||||
const fileName = sanitizeFilename(originalName);
|
if (trimFilename && originalName.length > 40) {
|
||||||
|
// https://github.com/zadam/trilium/issues/2307
|
||||||
|
originalName = "image";
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileName = sanitizeFilename(originalName);
|
||||||
const parentNote = becca.getNote(parentNoteId);
|
const parentNote = becca.getNote(parentNoteId);
|
||||||
|
|
||||||
const {note} = noteService.createNewNote({
|
const {note} = noteService.createNewNote({
|
||||||
@ -95,6 +99,14 @@ function saveImage(parentNoteId, uploadBuffer, originalName, shrinkImageSwitch)
|
|||||||
processImage(uploadBuffer, originalName, shrinkImageSwitch).then(({buffer, imageFormat}) => {
|
processImage(uploadBuffer, originalName, shrinkImageSwitch).then(({buffer, imageFormat}) => {
|
||||||
sql.transactional(() => {
|
sql.transactional(() => {
|
||||||
note.mime = getImageMimeFromExtension(imageFormat.ext);
|
note.mime = getImageMimeFromExtension(imageFormat.ext);
|
||||||
|
|
||||||
|
if (!originalName.includes(".")) {
|
||||||
|
originalName += "." + imageFormat.ext;
|
||||||
|
|
||||||
|
note.setLabel('originalFileName', originalName);
|
||||||
|
note.title = sanitizeFilename(originalName);
|
||||||
|
}
|
||||||
|
|
||||||
note.save();
|
note.save();
|
||||||
|
|
||||||
note.setContent(buffer);
|
note.setContent(buffer);
|
||||||
|
@ -270,7 +270,7 @@ async function downloadImage(noteId, imageUrl) {
|
|||||||
const title = path.basename(parsedUrl.pathname);
|
const title = path.basename(parsedUrl.pathname);
|
||||||
|
|
||||||
const imageService = require('../services/image');
|
const imageService = require('../services/image');
|
||||||
const {note} = imageService.saveImage(noteId, imageBuffer, title, true);
|
const {note} = imageService.saveImage(noteId, imageBuffer, title, true, true);
|
||||||
|
|
||||||
note.addLabel('imageUrl', imageUrl);
|
note.addLabel('imageUrl', imageUrl);
|
||||||
|
|
||||||
@ -305,7 +305,7 @@ function downloadImages(noteId, content) {
|
|||||||
const imageBuffer = Buffer.from(imageBase64, 'base64');
|
const imageBuffer = Buffer.from(imageBase64, 'base64');
|
||||||
|
|
||||||
const imageService = require('../services/image');
|
const imageService = require('../services/image');
|
||||||
const {note} = imageService.saveImage(noteId, imageBuffer, "inline image", true);
|
const {note} = imageService.saveImage(noteId, imageBuffer, "inline image", true, true);
|
||||||
|
|
||||||
content = content.substr(0, imageMatch.index)
|
content = content.substr(0, imageMatch.index)
|
||||||
+ `<img src="api/images/${note.noteId}/${note.title}"`
|
+ `<img src="api/images/${note.noteId}/${note.title}"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user