mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-04 23:20:07 +00:00
## Summary Extracts shared formatting and network utilities into dedicated workspace package. ## Changes - **What**: Created `@comfyorg/shared-frontend-utils` package containing formatUtil and networkUtil - **Breaking**: None - utilities remain accessible via path aliases in `tsconfig` Split `createAnnotatedPath` and `electronMirrorCheck` out and left in frontend, due to their tightly-coupled nature. See [discussion on this PR](https://github.com/Comfy-Org/ComfyUI_frontend/pull/5843#issuecomment-3344724727).
24 lines
932 B
TypeScript
24 lines
932 B
TypeScript
import type { ResultItem } from '@/schemas/apiSchema'
|
|
|
|
const hasAnnotation = (filepath: string): boolean =>
|
|
/\[(input|output|temp)\]/i.test(filepath)
|
|
|
|
const createAnnotation = (filepath: string, rootFolder = 'input'): string =>
|
|
!hasAnnotation(filepath) && rootFolder !== 'input' ? ` [${rootFolder}]` : ''
|
|
|
|
const createPath = (filename: string, subfolder = ''): string =>
|
|
subfolder ? `${subfolder}/${filename}` : filename
|
|
|
|
/** Creates annotated filepath in format used by folder_paths.py */
|
|
export function createAnnotatedPath(
|
|
item: string | ResultItem,
|
|
options: { rootFolder?: string; subfolder?: string } = {}
|
|
): string {
|
|
const { rootFolder = 'input', subfolder } = options
|
|
if (typeof item === 'string')
|
|
return `${createPath(item, subfolder)}${createAnnotation(item, rootFolder)}`
|
|
return `${createPath(item.filename ?? '', item.subfolder)}${
|
|
item.type ? createAnnotation(item.type, rootFolder) : ''
|
|
}`
|
|
}
|