From 412375e92f7c2508474bf02be06a86de260c468c Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 5 Jun 2019 21:27:07 +0200 Subject: [PATCH 1/6] import should recognize all suported code note file types, fixes #554 --- src/services/import/single.js | 44 ++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/services/import/single.js b/src/services/import/single.js index 578187efe..1fb682421 100644 --- a/src/services/import/single.js +++ b/src/services/import/single.js @@ -47,8 +47,46 @@ const CODE_MIME_TYPES = { 'text/x-yaml': true }; +// extensions missing in mime-db +const EXTENSION_TO_MIME = { + ".cs": "text/x-csharp", + ".clj": "text/x-clojure", + ".erl": "text/x-erlang", + ".hrl": "text/x-erlang", + ".feature": "text/x-feature", + ".go": "text/x-go", + ".groovy": "text/x-groovy", + ".hs": "text/x-haskell", + ".lhs": "text/x-haskell", + ".http": "message/http", + ".kt": "text/x-kotlin", + ".m": "text/x-objectivec", + ".py": "text/x-python", + ".rb": "text/x-ruby", + ".scala": "text/x-scala", + ".swift": "text/x-swift" +}; + +function getMime(fileName) { + if (fileName.toLowerCase() === 'dockerfile') { + return "text/x-dockerfile"; + } + + const ext = path.extname(fileName).toLowerCase(); + + console.log("EXT", ext); + + if (ext in EXTENSION_TO_MIME) { + console.log(EXTENSION_TO_MIME[ext]); + + return EXTENSION_TO_MIME[ext]; + } + + return mimeTypes.lookup(fileName); +} + async function importSingleFile(importContext, file, parentNote) { - const mime = mimeTypes.lookup(file.originalname); + const mime = getMime(file.originalname); if (importContext.textImportedAsText) { if (mime === 'text/html') { @@ -87,7 +125,7 @@ async function importFile(importContext, file, parentNote) { target: 'into', isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(), type: 'file', - mime: mimeTypes.lookup(originalName), + mime: getMime(originalName), attributes: [ { type: "label", name: "originalFileName", value: originalName }, { type: "label", name: "fileSize", value: size } @@ -102,7 +140,7 @@ async function importFile(importContext, file, parentNote) { async function importCodeNote(importContext, file, parentNote) { const title = getFileNameWithoutExtension(file.originalname); const content = file.buffer.toString("UTF-8"); - const detectedMime = mimeTypes.lookup(file.originalname); + const detectedMime = getMime(file.originalname); const mime = CODE_MIME_TYPES[detectedMime] === true ? detectedMime : CODE_MIME_TYPES[detectedMime]; const {note} = await noteService.createNote(parentNote.noteId, title, content, { From b389ec5ea335f5bf2c874242be1fe2c244008636 Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 3 Jun 2019 20:36:37 +0200 Subject: [PATCH 2/6] enter/leave protected session button is not refreshed after entering from note detail (not dialog), fixes #555 (cherry picked from commit 0a0663be69cda302a3bfea6b084c48b8b9ba3ec3) --- src/public/javascripts/services/protected_session.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/public/javascripts/services/protected_session.js b/src/public/javascripts/services/protected_session.js index e732d9355..233d01e04 100644 --- a/src/public/javascripts/services/protected_session.js +++ b/src/public/javascripts/services/protected_session.js @@ -55,11 +55,11 @@ async function setupProtectedSession(password) { protectedSessionDeferred.resolve(true); protectedSessionDeferred = null; - - $enterProtectedSessionButton.hide(); - $leaveProtectedSessionButton.show(); } + $enterProtectedSessionButton.hide(); + $leaveProtectedSessionButton.show(); + infoService.showMessage("Protected session has been started."); } From 19a154c2f4490b55bc4d89edffca77e3d0038298 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 5 Jun 2019 22:07:12 +0200 Subject: [PATCH 3/6] fix direct migration from 0.30 to 0.32, closes #557 --- src/services/sync_table.js | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/services/sync_table.js b/src/services/sync_table.js index 4ac6b5972..f5465e234 100644 --- a/src/services/sync_table.js +++ b/src/services/sync_table.js @@ -62,26 +62,33 @@ async function cleanupSyncRowsForMissingEntities(entityName, entityKey) { } async function fillSyncRows(entityName, entityKey, condition = '') { - await cleanupSyncRowsForMissingEntities(entityName, entityKey); + try { + await cleanupSyncRowsForMissingEntities(entityName, entityKey); - const entityIds = await sql.getColumn(`SELECT ${entityKey} FROM ${entityName}` - + (condition ? ` WHERE ${condition}` : '')); + const entityIds = await sql.getColumn(`SELECT ${entityKey} FROM ${entityName}` + + (condition ? ` WHERE ${condition}` : '')); - for (const entityId of entityIds) { - const existingRows = await sql.getValue("SELECT COUNT(id) FROM sync WHERE entityName = ? AND entityId = ?", [entityName, entityId]); + for (const entityId of entityIds) { + const existingRows = await sql.getValue("SELECT COUNT(id) FROM sync WHERE entityName = ? AND entityId = ?", [entityName, entityId]); - // we don't want to replace existing entities (which would effectively cause full resync) - if (existingRows === 0) { - log.info(`Creating missing sync record for ${entityName} ${entityId}`); + // we don't want to replace existing entities (which would effectively cause full resync) + if (existingRows === 0) { + log.info(`Creating missing sync record for ${entityName} ${entityId}`); - await sql.insert("sync", { - entityName: entityName, - entityId: entityId, - sourceId: "SYNC_FILL", - utcSyncDate: dateUtils.utcNowDateTime() - }); + await sql.insert("sync", { + entityName: entityName, + entityId: entityId, + sourceId: "SYNC_FILL", + utcSyncDate: dateUtils.utcNowDateTime() + }); + } } } + catch (e) { + // this is to fix migration from 0.30 to 0.32, can be removed later + // see https://github.com/zadam/trilium/issues/557 + log.error(`Filling sync rows failed for ${entityName} ${entityKey} with error "${e.message}", continuing`); + } } async function fillAllSyncRows() { From 97a258c0c61177f7a3578f41691d2bd9a600f5b8 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 5 Jun 2019 22:50:03 +0200 Subject: [PATCH 4/6] include sync version in sync seed request, #559 --- src/services/setup.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/services/setup.js b/src/services/setup.js index d06ec46e7..b56284316 100644 --- a/src/services/setup.js +++ b/src/services/setup.js @@ -5,6 +5,7 @@ const repository = require('./repository'); const optionService = require('./options'); const syncOptions = require('./sync_options'); const request = require('./request'); +const appInfo = require('./app_info'); async function hasSyncServerSchemaAndSeed() { const response = await requestToSyncServer('GET', '/api/setup/status'); @@ -27,7 +28,8 @@ async function sendSeedToSyncServer() { log.info("Initiating sync to server"); await requestToSyncServer('POST', '/api/setup/sync-seed', { - options: await getSyncSeedOptions() + options: await getSyncSeedOptions(), + syncVersion: appInfo.syncVersion }); // this is completely new sync, need to reset counters. If this would not be new sync, From 547ad7221debb996b3994b86c7f4f250a4f91606 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 5 Jun 2019 22:53:34 +0200 Subject: [PATCH 5/6] release 0.32.4 --- package.json | 2 +- src/services/build.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b842c4ae1..23c476dac 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "trilium", "productName": "Trilium Notes", "description": "Trilium Notes", - "version": "0.32.3", + "version": "0.32.4", "license": "AGPL-3.0-only", "main": "electron.js", "bin": { diff --git a/src/services/build.js b/src/services/build.js index fc97035b2..00ab27bba 100644 --- a/src/services/build.js +++ b/src/services/build.js @@ -1 +1 @@ -module.exports = { buildDate:"2019-06-02T14:04:32+02:00", buildRevision: "fbfb7b3b306d48ba9e7c09b7218af7354c58a3d1" }; +module.exports = { buildDate:"2019-06-05T22:53:34+02:00", buildRevision: "97a258c0c61177f7a3578f41691d2bd9a600f5b8" }; From f3ed7e936deffa157265295c81615101552d854c Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 6 Jun 2019 21:16:12 +0200 Subject: [PATCH 6/6] focus input on shown modal in branch prefix dialog, fixes #560 --- package-lock.json | 2 +- src/public/javascripts/dialogs/branch_prefix.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8688a2172..d02cd1624 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "trilium", - "version": "0.32.2-beta", + "version": "0.32.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/public/javascripts/dialogs/branch_prefix.js b/src/public/javascripts/dialogs/branch_prefix.js index ef8f77b57..152a3c526 100644 --- a/src/public/javascripts/dialogs/branch_prefix.js +++ b/src/public/javascripts/dialogs/branch_prefix.js @@ -21,7 +21,7 @@ async function showDialog() { branchId = currentNode.data.branchId; const branch = await treeCache.getBranch(branchId); - $treePrefixInput.val(branch.prefix).focus(); + $treePrefixInput.val(branch.prefix); const noteTitle = await treeUtils.getNoteTitle(currentNode.data.noteId); @@ -46,6 +46,8 @@ $form.submit(() => { return false; }); +$dialog.on('shown.bs.modal', () => $treePrefixInput.focus()); + export default { showDialog }; \ No newline at end of file