File size: 601 Bytes
b594e33
 
c1f12bf
 
 
 
b594e33
c1f12bf
 
 
 
cdd4011
 
 
c1f12bf
cdd4011
 
c1f12bf
 
 
cdd4011
 
c1f12bf
cdd4011
c1f12bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/**
 * Take a string, try to unpack it as JSON to validate it, return a string
 *
 * @param something
 * @param defaultComfyWorkflowTemplate
 * @returns
 */
export function getValidComfyWorkflowTemplate(
  something: any,
  defaultComfyWorkflowTemplate: string
) {
  const strValue = `${something || defaultComfyWorkflowTemplate}`
  try {
    const workflow = JSON.parse(strValue)
    if (typeof workflow === 'object') {
      return strValue
    } else {
      throw new Error(
        `this doesn't look like a ComfyUI workflow template string`
      )
    }
  } catch (err) {
    return '{}'
  }
}