moved workflow sharing from api to server side actions (#257)

This commit is contained in:
arkml 2025-09-15 21:26:01 +05:30 committed by GitHub
parent be4e17b5a5
commit 14fd7214c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 76 additions and 127 deletions

View file

@ -10,6 +10,7 @@ import { PipelineConfig } from "../entities/pipeline_config";
import { ToolConfig } from "../entities/tool_config";
import { App as ChatApp } from "../playground/app";
import { z } from "zod";
import { createSharedWorkflowFromJson } from '@/app/actions/shared-workflow.actions';
import { Button, Dropdown, DropdownItem, DropdownMenu, DropdownTrigger, Spinner, Tooltip, Modal, ModalContent, ModalHeader, ModalBody, ModalFooter, useDisclosure } from "@heroui/react";
import { PromptConfig } from "../entities/prompt_config";
import { DataSourceConfig } from "../entities/datasource_config";
@ -1603,22 +1604,13 @@ export function WorkflowEditor({
document.body.removeChild(a);
}
// Share: upload JSON to server to get a share ID and reveal copy button
// Share: create a shared workflow via server action to get an ID and reveal copy button
const [shareUrl, setShareUrl] = useState<string | null>(null);
async function handleShareWorkflow() {
try {
// POST to server to create a share token
const json = buildWorkflowExportJson();
const resp = await fetch('/api/shared-workflow', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: json,
});
if (!resp.ok) {
console.error('Failed to create share link');
return;
}
const data = await resp.json();
const data = await createSharedWorkflowFromJson(json);
const createUrl = `${window.location.origin}/projects?shared=${encodeURIComponent(data.id)}`;
setShareUrl(createUrl);
} catch (e) {

View file

@ -11,6 +11,7 @@ import { Button } from "@/components/ui/button";
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
import { TextareaWithSend } from "@/app/components/ui/textarea-with-send";
import { Workflow } from '../../lib/types/workflow_types';
import { loadSharedWorkflow } from '@/app/actions/shared-workflow.actions';
import { PictureImg } from '@/components/ui/picture-img';
import { Tabs, Tab } from "@/components/ui/tabs";
import { Project } from "@/src/entities/models/project";
@ -306,13 +307,7 @@ export function BuildAssistantSection() {
if (sharedId || importUrl) {
try {
setAutoCreateLoading(true);
const qs = sharedId ? `id=${encodeURIComponent(sharedId)}` : `url=${encodeURIComponent(importUrl!)}`;
const resp = await fetch(`/api/shared-workflow?${qs}`, { cache: 'no-store' });
if (!resp.ok) {
const data = await resp.json().catch(() => ({}));
throw new Error(data.error || `Failed to load shared workflow (${resp.status})`);
}
const workflowObj = await resp.json();
const workflowObj = await loadSharedWorkflow(sharedId || importUrl!);
await createProjectFromJsonWithOptions({
workflowJson: JSON.stringify(workflowObj),
router,

View file

@ -12,6 +12,7 @@ import { HorizontalDivider } from "@/components/ui/horizontal-divider";
import { Tooltip } from "@heroui/react";
import { BillingUpgradeModal } from "@/components/common/billing-upgrade-modal";
import { Workflow } from '@/app/lib/types/workflow_types';
import { loadSharedWorkflow } from '@/app/actions/shared-workflow.actions';
import { Modal } from '@/components/ui/modal';
import { Upload, Send, X } from "lucide-react";
@ -172,14 +173,8 @@ export function CreateProject({ defaultName, onOpenProjectPane, isProjectPaneOpe
setAutoCreateLoading(true);
try {
if (sharedId || importUrl) {
// Fetch workflow JSON via our API route
const qs = sharedId ? `id=${encodeURIComponent(sharedId)}` : `url=${encodeURIComponent(importUrl!)}`;
const resp = await fetch(`/api/shared-workflow?${qs}`, { cache: 'no-store' });
if (!resp.ok) {
const data = await resp.json().catch(() => ({}));
throw new Error(data.error || `Failed to load shared workflow (${resp.status})`);
}
const workflowObj = await resp.json();
// Load workflow via server action (supports id or URL)
const workflowObj = await loadSharedWorkflow(sharedId || importUrl!);
await createProjectFromJsonWithOptions({
workflowJson: JSON.stringify(workflowObj),
router,