LCOV - code coverage report
Current view: top level - src/platform/workflowErrors/missingModel/composables - useMissingModelDownload.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 45.5 % 22 10
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import {
       2              :   isTrustedHuggingFaceUrl,
       3              :   openGatedRepoPage
       4              : } from '@/platform/workflowErrors/missingModel/missingModelDownload'
       5              : import type { ModelWithUrl } from '@/platform/workflowErrors/missingModel/missingModelDownload'
       6              : import { fetchAndStoreModelMetadata } from '@/platform/workflowErrors/missingModel/missingModelMetadata'
       7              : import { useMissingModelDownloadStore } from '@/platform/workflowErrors/missingModel/missingModelDownloadStore'
       8              : import { useMissingModelStore } from '@/platform/workflowErrors/missingModel/missingModelStore'
       9              : 
      10          305 : export function useMissingModelDownload() {
      11          305 :   const store = useMissingModelStore()
      12              : 
      13           99 :   function fileSizeFor(url: string): number | undefined {
      14           99 :     return store.fileSizes[url]
      15              :   }
      16              : 
      17          230 :   function gatedRepoUrlFor(url: string): string | undefined {
      18          230 :     return store.gatedRepoUrls[url]
      19              :   }
      20              : 
      21           31 :   async function prefetchModelMetadata(url: string): Promise<void> {
      22           31 :     if (fileSizeFor(url) !== undefined || gatedRepoUrlFor(url)) return
      23              : 
      24            3 :     await fetchAndStoreModelMetadata(url, store)
      25              :   }
      26              : 
      27            0 :   function downloadMissingModel(model: ModelWithUrl): void {
      28            0 :     useMissingModelDownloadStore().download(model)
      29              :   }
      30              : 
      31              :   // Always try the bridge: it opens in the user's Electron session. isRemote()
      32              :   // describes the backend server, not the user, so it must not gate this. The
      33              :   // anchor fallback inside Electron hits shell.openExternal and strands the
      34              :   // provider cookies in the system browser.
      35            0 :   async function openModelAccessPage(repoUrl: string): Promise<void> {
      36            0 :     if (!isTrustedHuggingFaceUrl(repoUrl)) {
      37            0 :       console.warn('[missingModelDownload] Blocked untrusted access URL')
      38            0 :       return
      39              :     }
      40              : 
      41            0 :     const bridge = window.__comfyDesktop2
      42            0 :     if (bridge?.openModelAccessPage) {
      43            0 :       try {
      44            0 :         if (await bridge.openModelAccessPage(repoUrl)) return
      45              :       } catch (error: unknown) {
      46            0 :         console.error('Failed to open model access page in Desktop:', error)
      47              :       }
      48              :     }
      49              : 
      50            0 :     openGatedRepoPage(repoUrl)
      51              :   }
      52              : 
      53          305 :   return {
      54              :     fileSizeFor,
      55              :     gatedRepoUrlFor,
      56              :     prefetchModelMetadata,
      57              :     downloadMissingModel,
      58              :     openModelAccessPage
      59              :   }
      60              : }
        

Generated by: LCOV version 2.0-1