Skip to content

Image Pipeline Playground

feat(frontend/store): drop legacy load path from graph state

Mohammad Rajaeifd6cafb3bfcd
diff --git a/frontend/src/store/graphStore.ts b/frontend/src/store/graphStore.ts
index b32140c..ea1f86d 100644
--- a/frontend/src/store/graphStore.ts
+++ b/frontend/src/store/graphStore.ts
@@ -400,17 +400,9 @@ export const useGraphStore = create<GraphState>((set, get) => ({
previews.splice(index, 1)
if (index < files.length) files.splice(index, 1)
- let nextPath = String(node.data.params.path ?? '')
let nextBatchId = String(node.data.params.asset_batch_id ?? '')
if (previews.length === 0) {
- nextPath = ''
nextBatchId = ''
- } else if (files.length === 1) {
- nextPath = files[0]
- } else if (files.length > 1) {
- // Keep the batch folder so remaining files continue to load together.
- const parent = files[0]?.replace(/[\\/][^\\/]+$/, '')
- if (parent) nextPath = parent
}
set({
@@ -424,8 +416,8 @@ export const useGraphStore = create<GraphState>((set, get) => ({
uploadedFiles: files,
params: {
...item.data.params,
- path: nextPath,
asset_batch_id: nextBatchId,
+ ...(nextBatchId ? {} : { sample: '' }),
},
},
}
@@ -433,7 +425,7 @@ export const useGraphStore = create<GraphState>((set, get) => ({
),
workflowDirty: true,
})
- return { file: removedFile, path: nextPath, assetBatchId: nextBatchId }
+ return { file: removedFile, path: '', assetBatchId: nextBatchId }
},
setActiveNodeId: (nodeId) =>
@@ -619,12 +611,18 @@ export const useGraphStore = create<GraphState>((set, get) => ({
toGraphPayload: () => {
const { nodes, edges } = get()
return {
- nodes: nodes.map((node) => ({
- id: node.id,
- type: node.data.type,
- params: node.data.params,
- position: node.position,
- })),
+ nodes: nodes.map((node) => {
+ const params = { ...node.data.params }
+ if (node.data.type === 'load_image') {
+ delete params.path
+ }
+ return {
+ id: node.id,
+ type: node.data.type,
+ params,
+ position: node.position,
+ }
+ }),
edges: edges.map((edge) => {
const waypoints = (
edge.data as { waypoints?: { x: number; y: number }[] } | undefined
diff --git a/frontend/src/workflow/materializeSampleImages.ts b/frontend/src/workflow/materializeSampleImages.ts
index ac9b4c7..97425cd 100644
--- a/frontend/src/workflow/materializeSampleImages.ts
+++ b/frontend/src/workflow/materializeSampleImages.ts
@@ -1,27 +1,29 @@
-/** Turn template placeholder paths like examples/lena.png into real asset refs. */
+/** Turn template sample markers into real asset refs. */
-import {
- batchDisplayPath,
- batchFilePaths,
- batchPreviewUrls,
-} from '../api/assets'
+import { batchFilePaths, batchPreviewUrls } from '../api/assets'
import { useGraphStore } from '../store/graphStore'
import type { RegisterAssetsResponse } from '../types'
-function isExamplePlaceholder(path: string): boolean {
- return path.replace(/\\/g, '/').replace(/^\.\//, '').startsWith('examples/')
+function needsSampleImage(params: Record<string, unknown>): boolean {
+ const batchId = String(params.asset_batch_id ?? '').trim()
+ if (batchId) return false
+ const sample = String(params.sample ?? '').trim().toLowerCase()
+ if (sample === 'lena') return true
+ // Legacy templates used path: examples/...
+ const path = String(params.path ?? '')
+ .replace(/\\/g, '/')
+ .replace(/^\.\//, '')
+ return path.startsWith('examples/')
}
/**
- * For Load Image nodes that still point at examples/..., register the bundled
- * sample via /api/assets/sample (no FormData copy).
+ * For Load Image nodes that request the bundled sample, register it via
+ * /api/assets/sample (no FormData copy).
*/
export async function materializeSampleImages(): Promise<void> {
const { nodes, updateNodeParams, setLocalPreviews } = useGraphStore.getState()
const targets = nodes.filter(
- (node) =>
- node.data.type === 'load_image' &&
- isExamplePlaceholder(String(node.data.params.path ?? '')),
+ (node) => node.data.type === 'load_image' && needsSampleImage(node.data.params),
)
if (targets.length === 0) return
@@ -30,15 +32,14 @@ export async function materializeSampleImages(): Promise<void> {
throw new Error('Could not stage sample image')
}
const result = (await response.json()) as RegisterAssetsResponse
- const path = batchDisplayPath(result.batch)
const urls = batchPreviewUrls(result.batch)
const files = batchFilePaths(result.batch)
for (const node of targets) {
- // Share one registered batch across all example Load Image nodes.
+ // Share one registered batch across all sample Load Image nodes.
updateNodeParams(node.id, {
- path,
asset_batch_id: result.batch.id,
+ sample: 'lena',
})
setLocalPreviews(node.id, urls, files)
}
diff --git a/frontend/src/workflow/workflowActions.ts b/frontend/src/workflow/workflowActions.ts
index 11ed265..cd4dbb7 100644
--- a/frontend/src/workflow/workflowActions.ts
+++ b/frontend/src/workflow/workflowActions.ts
@@ -44,7 +44,7 @@ export function newWorkflow(): void {
export function saveWorkflow(): WorkflowRecord {
const state = useGraphStore.getState()
if (!state.workflowId) {
- throw new Error('No saved workflow — use Save As')
+ throw new Error('No saved workflow — save with a name first')
}
const record = upsertWorkflow(state.toWorkflowDocument())
state.markWorkflowClean(record)