mirror of
https://github.com/zadam/trilium.git
synced 2025-06-05 01:18:44 +02:00
image import/export related fixes
This commit is contained in:
parent
c3e1126489
commit
9de2927304
@ -1,9 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
const imageType = require('image-type');
|
||||
const imageService = require('../../services/image');
|
||||
const utils = require('../../services/utils');
|
||||
const dateNoteService = require('../../services/date_notes');
|
||||
const sql = require('../../services/sql');
|
||||
const noteService = require('../../services/notes');
|
||||
const passwordEncryptionService = require('../../services/password_encryption');
|
||||
const optionService = require('../../services/options');
|
||||
@ -36,9 +36,11 @@ async function uploadImage(req) {
|
||||
return [400, "Unknown image type: " + file.mimetype];
|
||||
}
|
||||
|
||||
const originalName = "Sender image." + imageType(file.buffer).ext;
|
||||
|
||||
const parentNote = await dateNoteService.getDateNote(req.headers['x-local-date']);
|
||||
|
||||
const {noteId} = await imageService.saveImage(file.buffer, "Sender image", parentNote.noteId, true);
|
||||
const {noteId} = await imageService.saveImage(file.buffer, originalName, parentNote.noteId, true);
|
||||
|
||||
return {
|
||||
noteId: noteId
|
||||
|
@ -32,11 +32,11 @@ async function exportToTar(exportContext, branch, format, res) {
|
||||
do {
|
||||
index = existingFileNames[lcFileName]++;
|
||||
|
||||
newName = lcFileName + "_" + index;
|
||||
newName = index + "_" + lcFileName;
|
||||
}
|
||||
while (newName in existingFileNames);
|
||||
|
||||
return fileName + "_" + index;
|
||||
return index + "_" + fileName;
|
||||
}
|
||||
else {
|
||||
existingFileNames[lcFileName] = 1;
|
||||
|
@ -26,8 +26,7 @@ async function saveImage(buffer, originalName, parentNoteId, shrinkImageSwitch)
|
||||
|
||||
const parentNote = await repository.getNote(parentNoteId);
|
||||
|
||||
const fileNameWithoutExtension = originalName.replace(/\.[^/.]+$/, "");
|
||||
const fileName = sanitizeFilename(fileNameWithoutExtension + "." + imageFormat.ext);
|
||||
const fileName = sanitizeFilename(originalName);
|
||||
|
||||
const {note} = await noteService.createNote(parentNoteId, fileName, finalImageBuffer, {
|
||||
target: 'into',
|
||||
|
@ -75,8 +75,6 @@ function getMime(fileName) {
|
||||
const ext = path.extname(fileName).toLowerCase();
|
||||
|
||||
if (ext in EXTENSION_TO_MIME) {
|
||||
console.log(EXTENSION_TO_MIME[ext]);
|
||||
|
||||
return EXTENSION_TO_MIME[ext];
|
||||
}
|
||||
|
||||
@ -108,7 +106,7 @@ async function importSingleFile(importContext, file, parentNote) {
|
||||
}
|
||||
|
||||
async function importImage(file, parentNote, importContext) {
|
||||
const {note} = await imageService.saveImage(file.buffer, getFileNameWithoutExtension(file.originalname), parentNote.noteId, importContext.shrinkImages);
|
||||
const {note} = await imageService.saveImage(file.buffer, file.originalname, parentNote.noteId, importContext.shrinkImages);
|
||||
|
||||
importContext.increaseProgressCount();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user