Merge branch 'stable'

# Conflicts:
#	package.json
This commit is contained in:
zadam 2019-07-11 22:27:27 +02:00
commit 706fc647ff
7 changed files with 29 additions and 21 deletions

6
package-lock.json generated
View File

@ -3065,9 +3065,9 @@
"integrity": "sha512-PcW2a0tyTuPHz3tWyYqtK6r1fZ3gp+3Sop8Ph+ZYN81Ob5rwmbHEzaqs10N3BEsaGTkh/ooniXK+WwszGlc2+Q=="
},
"electron": {
"version": "6.0.0-beta.11",
"resolved": "https://registry.npmjs.org/electron/-/electron-6.0.0-beta.11.tgz",
"integrity": "sha512-B6zh9c5pJ0BKKNkOEbF6vKXnBCWgtvY8LaUYDNeR9ttnPP0CCm0oovIoqP9/nN5gL8rlCoCgKWsjmiHu0jg7mA==",
"version": "6.0.0-beta.13",
"resolved": "https://registry.npmjs.org/electron/-/electron-6.0.0-beta.13.tgz",
"integrity": "sha512-q1pX18l4N6PH0iCoHXPmgqDNEX2slvMYZcxWXHlUFQodtvXq7bnsFfr6uvifMT5oSdfsCZtXXPK3/iK6PdODNQ==",
"dev": true,
"requires": {
"@types/node": "^10.12.18",

View File

@ -2,7 +2,7 @@
"name": "trilium",
"productName": "Trilium Notes",
"description": "Trilium Notes",
"version": "0.33.6",
"version": "0.33.7",
"license": "AGPL-3.0-only",
"main": "electron.js",
"bin": {
@ -76,7 +76,7 @@
},
"devDependencies": {
"devtron": "1.4.0",
"electron": "6.0.0-beta.11",
"electron": "6.0.0-beta.13",
"electron-builder": "20.44.4",
"electron-compile": "6.4.4",
"electron-installer-debian": "2.0.0",

View File

@ -1,5 +1,6 @@
"use strict";
const imageType = require('image-type');
const imageService = require('../../services/image');
const dateNoteService = require('../../services/date_notes');
const noteService = require('../../services/notes');
@ -11,9 +12,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

View File

@ -1 +1 @@
module.exports = { buildDate:"2019-07-02T22:26:05+02:00", buildRevision: "196264b8c2fc626e3114d65423c7110cff99ae85" };
module.exports = { buildDate:"2019-07-11T20:55:56+02:00", buildRevision: "a76dcb44ae1c1cef58b9a66041b183893745a944" };

View File

@ -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;
@ -46,24 +46,32 @@ async function exportToTar(exportContext, branch, format, res) {
}
function getDataFileName(note, baseFileName, existingFileNames) {
let extension;
const existingExtension = path.extname(baseFileName).toLowerCase();
let newExtension;
// following two are handled specifically since we always want to have these extensions no matter the automatic detection
// and/or existing detected extensions in the note name
if (note.type === 'text' && format === 'markdown') {
extension = 'md';
newExtension = 'md';
}
else if (note.type === 'text' && format === 'html') {
newExtension = 'html';
}
else if (note.mime === 'application/x-javascript' || note.mime === 'text/javascript') {
extension = 'js';
newExtension = 'js';
}
else if (existingExtension.length > 0) { // if the page already has an extension, then we'll just keep it
newExtension = null;
}
else {
extension = mimeTypes.extension(note.mime) || "dat";
newExtension = mimeTypes.extension(note.mime) || "dat";
}
let fileName = baseFileName;
const existingExtension = path.extname(fileName).toLowerCase();
// if the note is already named with extension (e.g. "jquery.js"), then it's silly to append exact same extension again
if (existingExtension !== extension) {
fileName += "." + extension;
if (newExtension && existingExtension !== "." + newExtension.toLowerCase()) {
fileName += "." + newExtension;
}
return getUniqueFilename(existingFileNames, fileName);

View File

@ -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',

View File

@ -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();