mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 19:05:59 +01:00
store images in notes, basic structure
This commit is contained in:
52
src/public/javascripts/services/note_detail_image.js
Normal file
52
src/public/javascripts/services/note_detail_image.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import utils from "./utils.js";
|
||||
import server from "./server.js";
|
||||
import protectedSessionHolder from "./protected_session_holder.js";
|
||||
import noteDetailService from "./note_detail.js";
|
||||
|
||||
const $noteDetailFile = $('#note-detail-file');
|
||||
|
||||
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();
|
||||
|
||||
const attributes = await server.get('notes/' + currentNote.noteId + '/attributes');
|
||||
const attributeMap = utils.toObject(attributes, l => [l.name, l.value]);
|
||||
|
||||
$noteDetailFile.show();
|
||||
|
||||
$fileFileName.text(attributeMap.originalFileName);
|
||||
$fileFileSize.text(attributeMap.fileSize + " bytes");
|
||||
$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
|
||||
return utils.getHost() + "/api/notes/" + noteDetailService.getCurrentNoteId()
|
||||
+ "/download?protectedSessionId=" + encodeURIComponent(protectedSessionHolder.getProtectedSessionId());
|
||||
}
|
||||
|
||||
export default {
|
||||
show,
|
||||
getContent: () => null,
|
||||
focus: () => null,
|
||||
onNoteChange: () => null,
|
||||
cleanup: () => null
|
||||
}
|
||||
Reference in New Issue
Block a user