Skip to content

Build your personal knowledge base with Trilium Notes

feat(backend-log): add download button

Elian Doran385f41889310
diff --git a/apps/client/src/services/open.ts b/apps/client/src/services/open.ts
index d983125260..b40ed0116e 100644
--- a/apps/client/src/services/open.ts
+++ b/apps/client/src/services/open.ts
@@ -39,7 +39,10 @@ function download(url: string) {
}
export function downloadFileNote(note: FNote, parentComponent: Component | null, ntxId: string | null | undefined) {
- if (note.type === "file" && note.mime === "application/pdf" && parentComponent) {
+ if (parentComponent && (
+ (note.type === "file" && note.mime === "application/pdf")
+ || note.noteId === "_backendLog"
+ )) {
// Special handling, manages its own downloading process.
parentComponent.triggerEvent("customDownload", { ntxId });
return;
diff --git a/apps/client/src/services/utils.ts b/apps/client/src/services/utils.ts
index 3936c92a7c..5a36c35580 100644
--- a/apps/client/src/services/utils.ts
+++ b/apps/client/src/services/utils.ts
@@ -930,6 +930,7 @@ export default {
createImageSrcUrl,
downloadAsSvg,
downloadAsPng,
+ triggerDownload,
compareVersions,
isUpdateAvailable,
isLaunchBarConfig
diff --git a/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx b/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx
index 15120fd2aa..c2b01877ea 100644
--- a/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx
+++ b/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx
@@ -76,6 +76,7 @@ export default function NoteActionsCustom(props: NoteActionsCustomProps) {
<DisplayModeSwitcher {...innerProps} />
<SaveToNoteButton {...innerProps} />
<RefreshButton {...innerProps} />
+ {innerProps.note.noteId === "_backendLog" && <DownloadFileButton {...innerProps} />}
<CopyReferenceToClipboardButton {...innerProps} />
<InAppHelpButton {...innerProps} />
<NoteActionsCustomInner {...innerProps} />
diff --git a/apps/client/src/widgets/type_widgets/code/BackendLog.tsx b/apps/client/src/widgets/type_widgets/code/BackendLog.tsx
index 1436c18135..a6e05aed39 100644
--- a/apps/client/src/widgets/type_widgets/code/BackendLog.tsx
+++ b/apps/client/src/widgets/type_widgets/code/BackendLog.tsx
@@ -4,6 +4,7 @@ import CodeMirror from "@triliumnext/codemirror";
import { useEffect, useRef, useState } from "preact/hooks";
import server from "../../../services/server";
+import utils from "../../../services/utils";
import { useNote, useNoteLabelOptionalBool, useTriliumEvent } from "../../react/hooks";
import { TypeWidgetProps } from "../type_widget";
import { CodeEditor } from "./Code";
@@ -33,6 +34,14 @@ export default function BackendLog({ ntxId, parentComponent }: TypeWidgetProps)
refresh();
});
+ // React to download button.
+ useTriliumEvent("customDownload", ({ ntxId: eventNtxId }) => {
+ if (eventNtxId !== ntxId) return;
+ const text = editorRef.current?.getText() ?? "";
+ const dataUrl = `data:text/plain;charset=utf-8,${encodeURIComponent(text)}`;
+ utils.triggerDownload(`trilium-backend-log-${new Date().toISOString().slice(0, 10)}.log`, dataUrl);
+ });
+
return (
<div className="backend-log-editor-container">
<CodeEditor