LCOV - code coverage report
Current view: top level - src/scripts/metadata - json.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 77.3 % 22 17
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import { isObject } from 'es-toolkit/compat'
       2              : 
       3              : import { parseJsonWithNonFinite } from '@/utils/jsonUtil'
       4              : 
       5         1035 : export function getDataFromJSON(
       6              :   file: File
       7              : ): Promise<Record<string, object> | undefined> {
       8         1035 :   return new Promise<Record<string, object> | undefined>((resolve) => {
       9         1035 :     const reader = new FileReader()
      10         1035 :     reader.onload = async () => {
      11         1035 :       try {
      12         1035 :         if (typeof reader.result !== 'string') {
      13            0 :           resolve(undefined)
      14            0 :           return
      15              :         }
      16         1035 :         const jsonContent = parseJsonWithNonFinite<Record<string, unknown>>(
      17              :           reader.result
      18              :         )
      19         1035 :         if (jsonContent.templates) {
      20            0 :           resolve({ templates: jsonContent.templates })
      21            0 :           return
      22              :         }
      23         1035 :         if (isApiJson(jsonContent)) {
      24            5 :           resolve({ prompt: jsonContent })
      25            5 :           return
      26              :         }
      27         1030 :         resolve({ workflow: jsonContent })
      28              :       } catch {
      29            0 :         resolve(undefined)
      30              :       }
      31              :     }
      32         1035 :     reader.onerror = () => resolve(undefined)
      33         1035 :     reader.onabort = () => resolve(undefined)
      34         1035 :     reader.readAsText(file)
      35              :   })
      36              : }
      37              : 
      38         1035 : function isApiJson(data: unknown) {
      39         1035 :   return isObject(data) && Object.values(data).every((v) => v.class_type)
      40              : }
        

Generated by: LCOV version 2.0-1