2018-03-28 10:11:06 +08:00
|
|
|
import utils from "./utils.js";
|
|
|
|
import server from "./server.js";
|
|
|
|
import protectedSessionHolder from "./protected_session_holder.js";
|
|
|
|
import noteDetailService from "./note_detail.js";
|
|
|
|
|
2018-11-08 17:30:35 +08:00
|
|
|
const $component = $('#note-detail-file');
|
2018-03-28 10:11:06 +08:00
|
|
|
|
|
|
|
const $fileFileName = $("#file-filename");
|
|
|
|
const $fileFileType = $("#file-filetype");
|
|
|
|
const $fileFileSize = $("#file-filesize");
|
|
|
|
const $fileDownload = $("#file-download");
|
|
|
|
const $fileOpen = $("#file-open");
|
|
|
|
|
|
|
|
async function show() {
|
|
|
|
const currentNote = noteDetailService.getCurrentNote();
|
|
|
|
|
2018-08-10 02:55:16 +08:00
|
|
|
const attributes = await server.get('notes/' + currentNote.noteId + '/attributes');
|
|
|
|
const attributeMap = utils.toObject(attributes, l => [l.name, l.value]);
|
2018-03-28 10:11:06 +08:00
|
|
|
|
2018-11-08 17:30:35 +08:00
|
|
|
$component.show();
|
2018-03-28 10:11:06 +08:00
|
|
|
|
2018-08-20 03:42:03 +08:00
|
|
|
$fileFileName.text(attributeMap.originalFileName);
|
|
|
|
$fileFileSize.text(attributeMap.fileSize + " bytes");
|
2018-03-28 10:11:06 +08:00
|
|
|
$fileFileType.text(currentNote.mime);
|
|
|
|
}
|
|
|
|
|
|
|
|
$fileDownload.click(() => utils.download(getFileUrl()));
|
|
|
|
|
|
|
|
$fileOpen.click(() => {
|
|
|
|
if (utils.isElectron()) {
|
|
|
|
const open = require("open");
|
|
|
|
|
|
|
|
open(getFileUrl());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
window.location.href = getFileUrl();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function getFileUrl() {
|
|
|
|
// electron needs absolute URL so we extract current host, port, protocol
|
2018-04-02 08:50:58 +08:00
|
|
|
return utils.getHost() + "/api/notes/" + noteDetailService.getCurrentNoteId()
|
|
|
|
+ "/download?protectedSessionId=" + encodeURIComponent(protectedSessionHolder.getProtectedSessionId());
|
2018-03-28 10:11:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
show,
|
|
|
|
getContent: () => null,
|
2018-09-03 22:05:28 +08:00
|
|
|
focus: () => null,
|
2018-10-31 19:29:01 +08:00
|
|
|
onNoteChange: () => null,
|
|
|
|
cleanup: () => null
|
2018-03-28 10:11:06 +08:00
|
|
|
}
|