mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
attachment download now works also in electron, added option to open the attachment
This commit is contained in:
parent
78e8c15786
commit
aa2bbc6575
@ -15,6 +15,8 @@ require('electron-debug')();
|
|||||||
// Prevent window being garbage collected
|
// Prevent window being garbage collected
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
|
|
||||||
|
require('electron-dl')({ saveAs: true });
|
||||||
|
|
||||||
function onClosed() {
|
function onClosed() {
|
||||||
// Dereference the window
|
// Dereference the window
|
||||||
// For multiple windows store them in an array
|
// For multiple windows store them in an array
|
||||||
|
72
package-lock.json
generated
72
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "trilium",
|
"name": "trilium",
|
||||||
"version": "0.6.1",
|
"version": "0.6.2",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -3206,6 +3206,16 @@
|
|||||||
"electron-localshortcut": "3.1.0"
|
"electron-localshortcut": "3.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"electron-dl": {
|
||||||
|
"version": "1.11.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/electron-dl/-/electron-dl-1.11.0.tgz",
|
||||||
|
"integrity": "sha512-iL9qHzzWOuL9bus+UT+P72SwrDQcFTV6QHqcbhwgqjCC9/K5jhdRzG0dIMB3TzYlk6rmApanPqh9DvWykwIH1Q==",
|
||||||
|
"requires": {
|
||||||
|
"ext-name": "5.0.0",
|
||||||
|
"pupa": "1.0.0",
|
||||||
|
"unused-filename": "1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"electron-download": {
|
"electron-download": {
|
||||||
"version": "3.3.0",
|
"version": "3.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/electron-download/-/electron-download-3.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/electron-download/-/electron-download-3.3.0.tgz",
|
||||||
@ -4374,6 +4384,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"ext-list": {
|
||||||
|
"version": "2.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/ext-list/-/ext-list-2.2.2.tgz",
|
||||||
|
"integrity": "sha512-u+SQgsubraE6zItfVA0tBuCBhfU9ogSRnsvygI7wht9TS510oLkBRXBsqopeUG/GBOIQyKZO9wjTqIu/sf5zFA==",
|
||||||
|
"requires": {
|
||||||
|
"mime-db": "1.30.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ext-name": {
|
||||||
|
"version": "5.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ext-name/-/ext-name-5.0.0.tgz",
|
||||||
|
"integrity": "sha512-yblEwXAbGv1VQDmow7s38W77hzAgJAO50ztBLMcUyUBfxv1HC+LGwtiEN+Co6LtlqT/5uwVOxsD4TNIilWhwdQ==",
|
||||||
|
"requires": {
|
||||||
|
"ext-list": "2.2.2",
|
||||||
|
"sort-keys-length": "1.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"extend": {
|
"extend": {
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz",
|
||||||
@ -5922,8 +5949,7 @@
|
|||||||
"is-plain-obj": {
|
"is-plain-obj": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz",
|
||||||
"integrity": "sha1-caUMhCnfync8kqOQpKA7OfzVHT4=",
|
"integrity": "sha1-caUMhCnfync8kqOQpKA7OfzVHT4="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"is-png": {
|
"is-png": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
@ -7152,6 +7178,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"modify-filename": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/modify-filename/-/modify-filename-1.1.0.tgz",
|
||||||
|
"integrity": "sha1-mi3sg4Bvuy2XXyK+7IWcoms5OqE="
|
||||||
|
},
|
||||||
"moment": {
|
"moment": {
|
||||||
"version": "2.20.1",
|
"version": "2.20.1",
|
||||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.20.1.tgz",
|
"resolved": "https://registry.npmjs.org/moment/-/moment-2.20.1.tgz",
|
||||||
@ -7564,6 +7595,11 @@
|
|||||||
"mimic-fn": "1.1.0"
|
"mimic-fn": "1.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"open": {
|
||||||
|
"version": "0.0.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/open/-/open-0.0.5.tgz",
|
||||||
|
"integrity": "sha1-QsPhjslUZra/DcQvOilFw/DK2Pw="
|
||||||
|
},
|
||||||
"optimist": {
|
"optimist": {
|
||||||
"version": "0.6.1",
|
"version": "0.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz",
|
||||||
@ -8391,6 +8427,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
|
||||||
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4="
|
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4="
|
||||||
},
|
},
|
||||||
|
"pupa": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/pupa/-/pupa-1.0.0.tgz",
|
||||||
|
"integrity": "sha1-mpVopa9+ZXuEYqbp1TKHQ1YM7/Y="
|
||||||
|
},
|
||||||
"q": {
|
"q": {
|
||||||
"version": "1.5.1",
|
"version": "1.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
|
||||||
@ -9186,11 +9227,18 @@
|
|||||||
"version": "1.1.2",
|
"version": "1.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/sort-keys/-/sort-keys-1.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/sort-keys/-/sort-keys-1.1.2.tgz",
|
||||||
"integrity": "sha1-RBttTTRnmPG05J6JIK37oOVD+a0=",
|
"integrity": "sha1-RBttTTRnmPG05J6JIK37oOVD+a0=",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"is-plain-obj": "1.1.0"
|
"is-plain-obj": "1.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"sort-keys-length": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/sort-keys-length/-/sort-keys-length-1.0.1.tgz",
|
||||||
|
"integrity": "sha1-nLb09OnkgVWmqgZx7dM2/xR5oYg=",
|
||||||
|
"requires": {
|
||||||
|
"sort-keys": "1.1.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"source-map": {
|
"source-map": {
|
||||||
"version": "0.5.7",
|
"version": "0.5.7",
|
||||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz",
|
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz",
|
||||||
@ -10963,6 +11011,22 @@
|
|||||||
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
||||||
"integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw="
|
"integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw="
|
||||||
},
|
},
|
||||||
|
"unused-filename": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/unused-filename/-/unused-filename-1.0.0.tgz",
|
||||||
|
"integrity": "sha1-00CID3GuIRXrqhMlvvBcxmhEacY=",
|
||||||
|
"requires": {
|
||||||
|
"modify-filename": "1.1.0",
|
||||||
|
"path-exists": "3.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"path-exists": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz",
|
||||||
|
"integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"unzip-response": {
|
"unzip-response": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/unzip-response/-/unzip-response-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/unzip-response/-/unzip-response-2.0.1.tgz",
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
"ejs": "~2.5.7",
|
"ejs": "~2.5.7",
|
||||||
"electron": "^1.8.2",
|
"electron": "^1.8.2",
|
||||||
"electron-debug": "^1.5.0",
|
"electron-debug": "^1.5.0",
|
||||||
|
"electron-dl": "^1.11.0",
|
||||||
"electron-in-page-search": "^1.2.4",
|
"electron-in-page-search": "^1.2.4",
|
||||||
"express": "~4.16.2",
|
"express": "~4.16.2",
|
||||||
"express-promise-wrap": "^0.2.2",
|
"express-promise-wrap": "^0.2.2",
|
||||||
@ -45,6 +46,7 @@
|
|||||||
"jimp": "^0.2.28",
|
"jimp": "^0.2.28",
|
||||||
"moment": "^2.20.1",
|
"moment": "^2.20.1",
|
||||||
"multer": "^1.3.0",
|
"multer": "^1.3.0",
|
||||||
|
"open": "0.0.5",
|
||||||
"rand-token": "^0.4.0",
|
"rand-token": "^0.4.0",
|
||||||
"request": "^2.83.0",
|
"request": "^2.83.0",
|
||||||
"request-promise": "^4.2.2",
|
"request-promise": "^4.2.2",
|
||||||
|
@ -18,6 +18,7 @@ const noteEditor = (function() {
|
|||||||
const $attachmentFileType = $("#attachment-filetype");
|
const $attachmentFileType = $("#attachment-filetype");
|
||||||
const $attachmentFileSize = $("#attachment-filesize");
|
const $attachmentFileSize = $("#attachment-filesize");
|
||||||
const $attachmentDownload = $("#attachment-download");
|
const $attachmentDownload = $("#attachment-download");
|
||||||
|
const $attachmentOpen = $("#attachment-open");
|
||||||
|
|
||||||
let editor = null;
|
let editor = null;
|
||||||
let codeEditor = null;
|
let codeEditor = null;
|
||||||
@ -271,9 +272,37 @@ const noteEditor = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$attachmentDownload.click(() => {
|
$attachmentDownload.click(() => {
|
||||||
window.location.href = "/api/attachments/download/" + getCurrentNoteId();
|
if (isElectron()) {
|
||||||
|
const remote = require('electron').remote;
|
||||||
|
|
||||||
|
remote.getCurrentWebContents().downloadURL(getAttachmentUrl());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
window.location.href = getAttachmentUrl();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$attachmentOpen.click(() => {
|
||||||
|
if (isElectron()) {
|
||||||
|
const open = require("open");
|
||||||
|
|
||||||
|
open(getAttachmentUrl());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
window.location.href = getAttachmentUrl();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function getAttachmentUrl() {
|
||||||
|
// electron needs absolute URL so we extract current host, port, protocol
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
const host = url.protocol + "//" + url.hostname + ":" + url.port;
|
||||||
|
|
||||||
|
const downloadUrl = "/api/attachments/download/" + getCurrentNoteId();
|
||||||
|
|
||||||
|
return host + downloadUrl;
|
||||||
|
}
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
$noteTitle.on('input', () => {
|
$noteTitle.on('input', () => {
|
||||||
noteChanged();
|
noteChanged();
|
||||||
|
@ -160,6 +160,8 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<button id="attachment-download" class="btn btn-primary" type="button">Download</button>
|
<button id="attachment-download" class="btn btn-primary" type="button">Download</button>
|
||||||
|
|
||||||
|
<button id="attachment-open" class="btn btn-primary" type="button">Open</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user