feat: add pipeline export as JSON file

This commit is contained in:
SnapOtter
2026-05-08 20:55:48 +08:00
parent c57d284232
commit e5939f7b5a
+28
View File
@@ -237,6 +237,27 @@ export function AutomatePage() {
[loadSteps],
);
const handleExportPipeline = useCallback((pipeline: SavedPipeline) => {
const exportData = {
format: "snapotter-pipeline" as const,
version: 1,
name: pipeline.name,
description: pipeline.description,
steps: pipeline.steps,
};
const blob = new Blob([JSON.stringify(exportData, null, 2)], { type: "application/json" });
const url = URL.createObjectURL(blob);
const slug = pipeline.name
.toLowerCase()
.replace(/[^a-z0-9]+/g, "-")
.replace(/^-|-$/g, "");
const a = document.createElement("a");
a.href = url;
a.download = `${slug || "pipeline"}.snapotter.json`;
a.click();
URL.revokeObjectURL(url);
}, []);
const handleDownloadAll = useCallback(() => {
if (!batchZipBlob) return;
const url = URL.createObjectURL(batchZipBlob);
@@ -522,6 +543,13 @@ export function AutomatePage() {
({p.steps.length} step{p.steps.length !== 1 ? "s" : ""})
</span>
</button>
<button
type="button"
onClick={() => handleExportPipeline(p)}
className="opacity-0 group-hover:opacity-100 p-1 rounded hover:bg-primary/10 text-muted-foreground hover:text-primary transition-all shrink-0"
>
<Download className="h-3 w-3" />
</button>
<button
type="button"
onClick={() => handleDeletePipeline(p.id)}