mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-24 10:50:35 +08:00
feat: Add custom download node function (#10659)
* add custom download node * use download node
This commit is contained in:
committed by
GitHub
parent
3388fe3478
commit
febb616063
12
src/frontend/src/customization/utils/custom-download-json.ts
Normal file
12
src/frontend/src/customization/utils/custom-download-json.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { FlowType } from "@/types/flow";
|
||||
|
||||
export async function customDownloadNodeJson(NodeFLow: FlowType) {
|
||||
// Fallback to browser download for web version
|
||||
const element = document.createElement("a");
|
||||
const file = new Blob([JSON.stringify(NodeFLow)], {
|
||||
type: "application/json",
|
||||
});
|
||||
element.href = URL.createObjectURL(file);
|
||||
element.download = `${NodeFLow?.name ?? "node"}.json`;
|
||||
element.click();
|
||||
}
|
||||
@ -258,6 +258,21 @@ const NodeToolbarComponent = memo(
|
||||
});
|
||||
}, [data.id, data.node?.documentation]);
|
||||
|
||||
const handleDownloadNode = useCallback(async () => {
|
||||
try {
|
||||
await downloadNode(flowComponent!);
|
||||
setSuccessData({
|
||||
title: `${flowComponent?.name || "Node"} downloaded successfully`,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error downloading node:", error);
|
||||
setErrorData({
|
||||
title: "Failed to download node",
|
||||
list: [error instanceof Error ? error.message : "Unknown error"],
|
||||
});
|
||||
}
|
||||
}, [flowComponent]);
|
||||
|
||||
useShortcuts({
|
||||
showOverrideModal,
|
||||
showModalAdvanced,
|
||||
@ -349,7 +364,7 @@ const NodeToolbarComponent = memo(
|
||||
shareComponent();
|
||||
break;
|
||||
case "Download":
|
||||
downloadNode(flowComponent!);
|
||||
handleDownloadNode();
|
||||
break;
|
||||
case "SaveAll":
|
||||
addFlow({
|
||||
|
||||
@ -27,6 +27,7 @@ import {
|
||||
getRightHandleId,
|
||||
} from "@/CustomNodes/utils/get-handle-id";
|
||||
import { INCOMPLETE_LOOP_ERROR_ALERT } from "@/constants/alerts_constants";
|
||||
import { customDownloadNodeJson } from "@/customization/utils/custom-download-json";
|
||||
import { customDownloadFlow } from "@/customization/utils/custom-reactFlowUtils";
|
||||
import useFlowStore from "@/stores/flowStore";
|
||||
import getFieldTitle from "../CustomNodes/utils/get-field-title";
|
||||
@ -1767,14 +1768,8 @@ export function createFlowComponent(
|
||||
return flowNode;
|
||||
}
|
||||
|
||||
export function downloadNode(NodeFLow: FlowType) {
|
||||
const element = document.createElement("a");
|
||||
const file = new Blob([JSON.stringify(NodeFLow)], {
|
||||
type: "application/json",
|
||||
});
|
||||
element.href = URL.createObjectURL(file);
|
||||
element.download = `${NodeFLow?.name ?? "node"}.json`;
|
||||
element.click();
|
||||
export async function downloadNode(NodeFLow: FlowType) {
|
||||
await customDownloadNodeJson(NodeFLow);
|
||||
}
|
||||
|
||||
export function updateComponentNameAndType(
|
||||
|
||||
Reference in New Issue
Block a user