Image Pipeline Playground
feat(frontend/inspector): choose required Save Image output folder
Mohammad Rajaei08485de51780
diff --git a/.gitignore b/.gitignoreindex d199e12..9b709ec 100644--- a/.gitignore+++ b/.gitignore@@ -19,6 +19,8 @@ backend/cache/*!backend/cache/.gitkeepbackend/uploads/*!backend/uploads/.gitkeep+backend/outputs/*+!backend/outputs/.gitkeep# Node / frontendnode_modules/diff --git a/backend/outputs/.gitkeep b/backend/outputs/.gitkeepnew file mode 100644index 0000000..e69de29diff --git a/frontend/src/features/inspector/NodeInspector.tsx b/frontend/src/features/inspector/NodeInspector.tsxindex c2e7df8..28307e1 100644--- a/frontend/src/features/inspector/NodeInspector.tsx+++ b/frontend/src/features/inspector/NodeInspector.tsx@@ -4,7 +4,6 @@ import { z } from 'zod'import { zodResolver } from '@hookform/resolvers/zod'import {Box,- Button,MenuItem,TextField,Typography,@@ -12,12 +11,7 @@ import {import { useGraphStore } from '../../store/graphStore'import type { ParamField } from '../../types'import { FileParamInput } from './FileParamInput'--const SAVE_PATH_TEMPLATES = [- { token: '{filename}', hint: 'source stem' },- { token: '{time}', hint: 'YYYYmmdd_HHMMSS' },- { token: '{index}', hint: 'sample index' },-] as const+import { SaveImageParams } from './SaveImageParams'function buildSchema(fields: ParamField[]) {const shape: Record<string, z.ZodTypeAny> = {}@@ -49,8 +43,9 @@ export function NodeInspector() {const meta = catalog.find((item) => item.type === selected?.data.type)const fields = meta?.params ?? []const schema = buildSchema(fields)+ const isSaveImage = selected?.data.type === 'save_image'- const { register, handleSubmit, reset, setValue, getValues, formState } = useForm({+ const { register, handleSubmit, reset, setValue, formState } = useForm({resolver: zodResolver(schema),defaultValues: selected?.data.params ?? {},})@@ -94,13 +89,6 @@ export function NodeInspector() {const commit = handleSubmit((values) => updateNodeParams(selected.id, values))- const insertPathTemplate = (token: string) => {- const current = String(getValues('path') ?? '')- const next = `${current}${token}`- setValue('path', next, { shouldDirty: true, shouldValidate: true })- updateNodeParams(selected.id, { path: next })- }-return (<Box sx={{ p: 2, height: '100%', overflow: 'auto' }}><Typography variant="subtitle1" sx={{ fontWeight: 700 }}>@@ -114,133 +102,97 @@ export function NodeInspector() {onChange={() => void commit()}sx={{ display: 'grid', gap: 1.5 }}>- {fields.length === 0 && (- <Typography variant="body2" color="text.secondary">- No configurable parameters.- </Typography>- )}- {fields.map((field) => {- if (field.type === 'file') {- return (- <FileParamInput- key={field.name}- field={field}- value={String(selected.data.params[field.name] ?? '')}- previewUrls={selected.data.localPreviewUrls ?? []}- uploadedFiles={selected.data.uploadedFiles ?? []}- onChange={(path) => {- setValue(field.name, path, { shouldDirty: true, shouldValidate: true })- updateNodeParams(selected.id, { [field.name]: path })- }}- onPreviews={(urls, files) => setLocalPreviews(selected.id, urls, files)}- onRemovePreview={(index) => {- const result = removeLocalPreview(selected.id, index)- if (!result) return- setValue(field.name, result.path, { shouldDirty: true, shouldValidate: true })- if (!result.file) return- void fetch(`/api/uploads?path=${encodeURIComponent(result.file)}`, {- method: 'DELETE',- })- }}- onBatchCount={(count) => {- setSampleCount(Math.max(1, count))- }}- />- )- }- if (field.type === 'select' && field.options) {- return (- <TextField- key={field.name}- select- size="small"- label={field.label}- helperText={field.description ?? undefined}- defaultValue={String(selected.data.params[field.name] ?? field.default ?? '')}- {...register(field.name)}- >- {field.options.map((option) => (- <MenuItem key={option} value={option}>- {option}- </MenuItem>- ))}- </TextField>- )- }-- const showSaveTemplates =- selected.data.type === 'save_image' && field.name === 'path'- const errorText = formState.errors[field.name]?.message as string | undefined-- return (- <Box key={field.name} sx={{ display: 'grid', gap: 0.75 }}>- <TextField- size="small"- label={field.label}- type={field.type === 'string' ? 'text' : 'number'}- helperText={errorText ?? field.description ?? undefined}- {...register(field.name)}- />- {showSaveTemplates && (- <Box>- <Typography- sx={{- fontSize: 10,- fontWeight: 700,- letterSpacing: '0.06em',- textTransform: 'uppercase',- color: 'rgba(244,241,234,0.4)',- mb: 0.5,+ {isSaveImage ? (+ <SaveImageParams+ directory={String(selected.data.params.directory ?? '')}+ filename={String(+ selected.data.params.filename ?? '{filename}_{index}.png',+ )}+ onDirectoryChange={(directory) => {+ setValue('directory', directory, { shouldDirty: true, shouldValidate: true })+ updateNodeParams(selected.id, { directory })+ }}+ onFilenameChange={(filename) => {+ setValue('filename', filename, { shouldDirty: true, shouldValidate: true })+ updateNodeParams(selected.id, { filename })+ }}+ />+ ) : (+ <>+ {fields.length === 0 && (+ <Typography variant="body2" color="text.secondary">+ No configurable parameters.+ </Typography>+ )}+ {fields.map((field) => {+ if (field.type === 'file') {+ return (+ <FileParamInput+ key={field.name}+ field={field}+ value={String(selected.data.params[field.name] ?? '')}+ previewUrls={selected.data.localPreviewUrls ?? []}+ uploadedFiles={selected.data.uploadedFiles ?? []}+ onChange={(path) => {+ setValue(field.name, path, { shouldDirty: true, shouldValidate: true })+ updateNodeParams(selected.id, { [field.name]: path })}}+ onPreviews={(urls, files) => setLocalPreviews(selected.id, urls, files)}+ onRemovePreview={(index) => {+ const result = removeLocalPreview(selected.id, index)+ if (!result) return+ setValue(field.name, result.path, {+ shouldDirty: true,+ shouldValidate: true,+ })+ if (!result.file) return+ void fetch(`/api/uploads?path=${encodeURIComponent(result.file)}`, {+ method: 'DELETE',+ })+ }}+ onBatchCount={(count) => {+ setSampleCount(Math.max(1, count))+ }}+ />+ )+ }+ if (field.type === 'select' && field.options) {+ return (+ <TextField+ key={field.name}+ select+ size="small"+ label={field.label}+ helperText={field.description ?? undefined}+ defaultValue={String(+ selected.data.params[field.name] ?? field.default ?? '',+ )}+ {...register(field.name)}>- Available templates- </Typography>- <Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 0.75 }}>- {SAVE_PATH_TEMPLATES.map((item) => (- <Button- key={item.token}- size="small"- variant="outlined"- className="nodrag nopan"- onClick={() => insertPathTemplate(item.token)}- sx={{- textTransform: 'none',- minWidth: 0,- px: 1,- py: 0.25,- borderColor: 'rgba(125,206,160,0.35)',- color: '#7dcea0',- fontFamily:- 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace',- fontSize: 11,- '&:hover': {- borderColor: 'rgba(125,206,160,0.6)',- bgcolor: 'rgba(125,206,160,0.08)',- },- }}- title={item.hint}- >- {item.token}- <Box- component="span"- sx={{- ml: 0.75,- color: 'rgba(244,241,234,0.4)',- fontFamily: '"IBM Plex Sans", "Segoe UI", sans-serif',- fontSize: 10,- fontWeight: 600,- }}- >- {item.hint}- </Box>- </Button>+ {field.options.map((option) => (+ <MenuItem key={option} value={option}>+ {option}+ </MenuItem>))}- </Box>- </Box>- )}- </Box>- )- })}+ </TextField>+ )+ }++ const errorText = formState.errors[field.name]?.message as string | undefined++ return (+ <TextField+ key={field.name}+ size="small"+ label={field.label}+ type={field.type === 'string' ? 'text' : 'number'}+ helperText={errorText ?? field.description ?? undefined}+ {...register(field.name)}+ />+ )+ })}+ </>+ )}</Box></Box>)diff --git a/frontend/src/features/inspector/SaveImageParams.tsx b/frontend/src/features/inspector/SaveImageParams.tsxnew file mode 100644index 0000000..650049f--- /dev/null+++ b/frontend/src/features/inspector/SaveImageParams.tsx@@ -0,0 +1,163 @@+import { useState } from 'react'+import { Box, Button, TextField, Typography } from '@mui/material'+import { notifyError, notifySuccess } from '../../notify'++const SAVE_PATH_TEMPLATES = [+ { token: '{filename}', hint: 'source stem' },+ { token: '{time}', hint: 'YYYYmmdd_HHMMSS' },+ { token: '{index}', hint: 'sample index' },+] as const++type SaveImageParamsProps = {+ directory: string+ filename: string+ onDirectoryChange: (directory: string) => void+ onFilenameChange: (filename: string) => void+}++export function SaveImageParams({+ directory,+ filename,+ onDirectoryChange,+ onFilenameChange,+}: SaveImageParamsProps) {+ const [busy, setBusy] = useState(false)+ const folderLabel = directory+ ? directory.replace(/\\/g, '/').split('/').filter(Boolean).at(-1) ?? directory+ : null++ const chooseFolder = async () => {+ setBusy(true)+ try {+ const response = await fetch('/api/outputs', { method: 'POST' })+ if (!response.ok) {+ throw new Error((await response.text()) || 'Could not create output folder')+ }+ const body = (await response.json()) as { path: string; name: string }+ onDirectoryChange(body.path)+ notifySuccess(`Output folder ready: ${body.name}`)+ } catch (error) {+ notifyError(error instanceof Error ? error.message : 'Folder selection failed')+ } finally {+ setBusy(false)+ }+ }++ const insertTemplate = (token: string) => {+ onFilenameChange(`${filename}${token}`)+ }++ return (+ <Box sx={{ display: 'grid', gap: 1.5 }}>+ <Box sx={{ display: 'grid', gap: 0.75 }}>+ <Typography+ sx={{+ fontSize: 10,+ fontWeight: 700,+ letterSpacing: '0.06em',+ textTransform: 'uppercase',+ color: 'rgba(244,241,234,0.4)',+ }}+ >+ Output folder (required)+ </Typography>+ <Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 1, alignItems: 'center' }}>+ <Button+ size="small"+ variant="outlined"+ disabled={busy}+ onClick={() => void chooseFolder()}+ sx={{ textTransform: 'none' }}+ >+ {directory ? 'Change folder' : 'Choose folder'}+ </Button>+ <Typography+ sx={{+ fontSize: 12,+ color: directory ? 'rgba(244,241,234,0.75)' : '#ff8a80',+ fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace',+ wordBreak: 'break-all',+ }}+ >+ {directory ? folderLabel : 'No folder selected'}+ </Typography>+ </Box>+ {directory && (+ <Typography+ sx={{+ fontSize: 11,+ color: 'rgba(244,241,234,0.4)',+ wordBreak: 'break-all',+ lineHeight: 1.4,+ }}+ title={directory}+ >+ {directory}+ </Typography>+ )}+ </Box>++ <TextField+ size="small"+ label="Filename"+ value={filename}+ onChange={(event) => onFilenameChange(event.target.value)}+ helperText="Templates: {filename}, {time}, {index}"+ />++ <Box>+ <Typography+ sx={{+ fontSize: 10,+ fontWeight: 700,+ letterSpacing: '0.06em',+ textTransform: 'uppercase',+ color: 'rgba(244,241,234,0.4)',+ mb: 0.5,+ }}+ >+ Available templates+ </Typography>+ <Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 0.75 }}>+ {SAVE_PATH_TEMPLATES.map((item) => (+ <Button+ key={item.token}+ size="small"+ variant="outlined"+ onClick={() => insertTemplate(item.token)}+ sx={{+ textTransform: 'none',+ minWidth: 0,+ px: 1,+ py: 0.25,+ borderColor: 'rgba(125,206,160,0.35)',+ color: '#7dcea0',+ fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace',+ fontSize: 11,+ '&:hover': {+ borderColor: 'rgba(125,206,160,0.6)',+ bgcolor: 'rgba(125,206,160,0.08)',+ },+ }}+ title={item.hint}+ >+ {item.token}+ <Box+ component="span"+ sx={{+ ml: 0.75,+ color: 'rgba(244,241,234,0.4)',+ fontFamily: '"IBM Plex Sans", "Segoe UI", sans-serif',+ fontSize: 10,+ fontWeight: 600,+ }}+ >+ {item.hint}+ </Box>+ </Button>+ ))}+ </Box>+ </Box>+ </Box>+ )+}