Files
ComfyUI_frontend/src/utils/createAnnotatedPath.ts
filtered ed5d258ab6 Extract shared utilities into workspace package (#5843)
## 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).
2025-09-29 18:52:40 -07:00

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) : ''
}`
}