From 042472801256bab6f2bf765b78053b7fea2545f1 Mon Sep 17 00:00:00 2001 From: siriusXT <1160925501@qq.com> Date: Thu, 7 Sep 2023 06:33:51 +0000 Subject: [PATCH] Add openAttachmentCustom --- .../app/components/root_command_executor.js | 6 +++--- src/public/app/services/open.js | 16 +++++++++----- .../widgets/buttons/attachments_actions.js | 21 +++++++++++++++++++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/public/app/components/root_command_executor.js b/src/public/app/components/root_command_executor.js index 08db59e62..29c3aab1d 100644 --- a/src/public/app/components/root_command_executor.js +++ b/src/public/app/components/root_command_executor.js @@ -44,8 +44,7 @@ export default class RootCommandExecutor extends Component { openNoteExternallyCommand() { const noteId = appContext.tabManager.getActiveContextNoteId(); - const mime = appContext.tabManager.getActiveContextNoteMime() - + const mime = appContext.tabManager.getActiveContextNoteMime(); if (noteId) { openService.openNoteExternally(noteId, mime); } @@ -53,8 +52,9 @@ export default class RootCommandExecutor extends Component { openNoteCustomCommand() { const noteId = appContext.tabManager.getActiveContextNoteId(); + const mime = appContext.tabManager.getActiveContextNoteMime(); if (noteId) { - openService.openNoteCustom(noteId); + openService.openNoteCustom(noteId, mime); } } diff --git a/src/public/app/services/open.js b/src/public/app/services/open.js index 43a5c9fa3..b3a1ae08b 100644 --- a/src/public/app/services/open.js +++ b/src/public/app/services/open.js @@ -41,12 +41,13 @@ function downloadAttachment(attachmentId) { download(url); } -async function openNoteCustom(noteId) { +async function openCustom(type, entityId, mime) { + checkType(type); if (!utils.isElectron() || utils.isMac()) { return; } - const resp = await server.post(`notes/${noteId}/save-to-tmp-dir`); + const resp = await server.post(`${type}/${entityId}/save-to-tmp-dir`); let filePath = resp.tmpFilePath; const {exec} = utils.dynamicRequire('child_process'); const platform = process.platform; @@ -71,7 +72,7 @@ async function openNoteCustom(noteId) { const terminal = terminals[index]; if (!terminal) { console.error('Open Note custom: No terminal found!'); - open(getFileUrl(noteId), {url: true}); + open(getFileUrl(entityId), {url: true}); return; } exec(`which ${terminal}`, (error, stdout, stderr) => { @@ -92,16 +93,20 @@ async function openNoteCustom(noteId) { exec(command, (err, stdout, stderr) => { if (err) { console.error("Open Note custom: ", err); - open(getFileUrl(noteId), {url: true}); + open(getFileUrl(entityId), {url: true}); return; } }); } else { console.log('Currently "Open Note custom" only supports linux and windows systems'); - open(getFileUrl(noteId), {url: true}); + open(getFileUrl(entityId), {url: true}); } } +const openNoteCustom = async (noteId, mime) => await openCustom('notes', noteId, mime); +const openAttachmentCustom = async (attachmentId, mime) => await openCustom('attachments', attachmentId, mime); + + function downloadRevision(noteId, revisionId) { const url = getUrlForDownload(`api/revisions/${revisionId}/download`); @@ -170,4 +175,5 @@ export default { openNoteExternally, openAttachmentExternally, openNoteCustom, + openAttachmentCustom, } diff --git a/src/public/app/widgets/buttons/attachments_actions.js b/src/public/app/widgets/buttons/attachments_actions.js index 313d1926b..c62030171 100644 --- a/src/public/app/widgets/buttons/attachments_actions.js +++ b/src/public/app/widgets/buttons/attachments_actions.js @@ -5,6 +5,7 @@ import toastService from "../../services/toast.js"; import ws from "../../services/ws.js"; import appContext from "../../components/app_context.js"; import openService from "../../services/open.js"; +import utils from "../../services/utils.js"; const TPL = `