Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/5693

Vanessa84eba12448a2
diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts
index f61b4f8f1f..8cfe0f4750 100644
--- a/app/src/menus/protyle.ts
+++ b/app/src/menus/protyle.ts
@@ -21,14 +21,16 @@ import {fetchPost} from "../util/fetch";
import {Constants} from "../constants";
import {writeText} from "../protyle/util/compatibility";
import {preventScroll} from "../protyle/scroll/preventScroll";
-import {getCurrentWindow} from "@electron/remote";
-import {clipboard} from "electron";
import {onGet} from "../protyle/util/onGet";
import {getAllModels} from "../layout/getAll";
import {pasteText} from "../protyle/util/paste";
/// #if !MOBILE
import {openFileById, updateBacklinkGraph} from "../editor/util";
/// #endif
+/// #if !BROWSER
+import {getCurrentWindow} from "@electron/remote";
+import {clipboard} from "electron";
+/// #endif
import {isMobile} from "../util/functions";
import {removeFoldHeading} from "../protyle/util/heading";
import {lineNumberRender} from "../protyle/markdown/highlightRender";
@@ -38,6 +40,7 @@ import {renameAsset} from "../editor/rename";
import {hasNextSibling} from "../protyle/wysiwyg/getBlock";
import {electronUndo} from "../protyle/undo";
import {pushBack} from "../mobile/util/MobileBackFoward";
+import {exportAsset} from "./util";
export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
const nodeElement = hasClosestBlock(element);
@@ -525,6 +528,9 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
}
}
}).element);
+ /// #if !BROWSER
+ window.siyuan.menus.menu.append(new MenuItem(exportAsset(imgElement.getAttribute("data-src"))).element);
+ /// #endif
window.siyuan.menus.menu.append(new MenuItem({
icon: "iconCut",
accelerator: "⌘X",
@@ -931,6 +937,9 @@ export const videoMenu = (protyle: IProtyle, nodeElement: Element, type: string)
}
});
}
+ /// #if !BROWSER
+ subMenus.push(exportAsset(src));
+ /// #endif
const VideoSrc = videoElement.getAttribute("src");
if (VideoSrc) {
return subMenus.concat(openMenu(VideoSrc, true) as IMenu[]);
diff --git a/app/src/menus/util.ts b/app/src/menus/util.ts
new file mode 100644
index 0000000000..ff11450264
--- /dev/null
+++ b/app/src/menus/util.ts
@@ -0,0 +1,25 @@
+/// #if !BROWSER
+import {dialog} from "@electron/remote";
+import {SaveDialogReturnValue} from "electron";
+/// #endif
+import {fetchPost} from "../util/fetch";
+import {getAssetName, pathPosix} from "../util/pathName";
+
+export const exportAsset = (src: string) => {
+ /// #if !BROWSER
+ return {
+ label: window.siyuan.languages.export,
+ icon: "iconUpload",
+ click() {
+ dialog.showSaveDialog({
+ defaultPath: getAssetName(src) + pathPosix().extname(src),
+ properties: ["showOverwriteConfirmation"],
+ }).then((result: SaveDialogReturnValue) => {
+ if (!result.canceled) {
+ fetchPost("/api/file/saveAs", {src, targe: result.filePath})
+ }
+ });
+ }
+ }
+ /// #endif
+}