download fixes for the sub-domain web deployment

This commit is contained in:
zadam 2019-11-22 20:35:17 +01:00
parent a16aaf7a81
commit cfb850acb2
6 changed files with 23 additions and 10 deletions

View File

@ -74,7 +74,7 @@ $form.on('submit', () => {
function exportBranch(branchId, type, format, version) { function exportBranch(branchId, type, format, version) {
taskId = utils.randomString(10); taskId = utils.randomString(10);
const url = utils.getHost() + `/api/notes/${branchId}/export/${type}/${format}/${version}/${taskId}`; const url = utils.getUrlForDownload(`api/notes/${branchId}/export/${type}/${format}/${version}/${taskId}`);
utils.download(url); utils.download(url);
} }

View File

@ -102,7 +102,9 @@ async function setContentPane() {
const $downloadButton = $('<button class="btn btn-sm btn-primary" type="button">Download</button>'); const $downloadButton = $('<button class="btn btn-sm btn-primary" type="button">Download</button>');
$downloadButton.on('click', () => { $downloadButton.on('click', () => {
utils.download(utils.getHost() + `/api/notes/${revisionItem.noteId}/revisions/${revisionItem.noteRevisionId}/download`); const url = utils.getUrlForDownload(`api/notes/${revisionItem.noteId}/revisions/${revisionItem.noteRevisionId}/download`);
utils.download(url);
}); });
$titleButtons.append($downloadButton); $titleButtons.append($downloadButton);

View File

@ -185,8 +185,7 @@ class NoteDetailBook {
} }
else if (type === 'file') { else if (type === 'file') {
function getFileUrl() { function getFileUrl() {
// electron needs absolute URL so we extract current host, port, protocol return utils.getUrlForDownload("api/notes/" + note.noteId + "/download");
return utils.getHost() + "/api/notes/" + note.noteId + "/download";
} }
const $downloadButton = $('<button class="file-download btn btn-primary" type="button">Download</button>'); const $downloadButton = $('<button class="file-download btn btn-primary" type="button">Download</button>');

View File

@ -87,8 +87,7 @@ class NoteDetailFile {
} }
getFileUrl() { getFileUrl() {
// electron needs absolute URL so we extract current host, port, protocol return utils.getUrlForDownload("api/notes/" + this.ctx.note.noteId + "/download");
return utils.getHost() + "/api/notes/" + this.ctx.note.noteId + "/download";
} }
show() {} show() {}

View File

@ -98,8 +98,7 @@ class NoteDetailImage {
} }
getFileUrl() { getFileUrl() {
// electron needs absolute URL so we extract current host, port, protocol return utils.getUrlForDownload(`api/notes/${this.ctx.note.noteId}/download`);
return utils.getHost() + `/api/notes/${this.ctx.note.noteId}/download`;
} }
show() {} show() {}

View File

@ -214,6 +214,20 @@ async function clearBrowserCache() {
} }
} }
/**
* @param url - should be without initial slash!!!
*/
function getUrlForDownload(url) {
if (isElectron()) {
// electron needs absolute URL so we extract current host, port, protocol
return getHost() + '/' + url;
}
else {
// web server can be deployed on subdomain so we need to use relative path
return url;
}
}
export default { export default {
reloadApp, reloadApp,
parseDate, parseDate,
@ -230,7 +244,6 @@ export default {
escapeHtml, escapeHtml,
stopWatch, stopWatch,
formatLabel, formatLabel,
getHost,
download, download,
toObject, toObject,
randomString, randomString,
@ -245,5 +258,6 @@ export default {
getMimeTypeClass, getMimeTypeClass,
closeActiveDialog, closeActiveDialog,
isHtmlEmpty, isHtmlEmpty,
clearBrowserCache clearBrowserCache,
getUrlForDownload
}; };