LCOV - code coverage report
Current view: top level - src/platform/workspace/components - UploadModelFileUpload.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 3.8 % 26 1
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1           16 : <template>
       2            0 :   <div class="flex min-h-0 flex-auto flex-col gap-6">
       3              :     <div
       4              :       class="flex min-h-0 flex-auto basis-0 flex-col gap-4 overflow-y-auto text-sm text-muted-foreground"
       5              :     >
       6              :       <div
       7              :         class="relative flex items-center gap-3 overflow-hidden rounded-lg bg-secondary px-4 py-3"
       8              :         v-bind="progressAttrs"
       9              :       >
      10              :         <div
      11              :           v-if="isTransferring"
      12              :           class="pointer-events-none absolute inset-y-0 left-0 bg-primary/30 transition-[width]"
      13              :           :style="{ width: `${percent}%` }"
      14              :         />
      15              :         <i aria-hidden="true" class="relative icon-[lucide--box] size-5" />
      16              :         <div class="relative flex min-w-0 flex-1 flex-col gap-1">
      17              :           <p class="m-0 truncate text-foreground" :title="state.file.name">
      18              :             {{ title }}
      19              :           </p>
      20              :           <p class="m-0">{{ sizeText }}</p>
      21              :         </div>
      22              :       </div>
      23              : 
      24              :       <p
      25              :         v-if="state.status === 'failed'"
      26              :         role="alert"
      27              :         class="m-0 text-destructive"
      28              :       >
      29              :         {{ state.error }}
      30              :       </p>
      31              : 
      32              :       <div
      33              :         v-if="state.status === 'chosen' || state.status === 'failed'"
      34              :         class="flex flex-col gap-2"
      35              :       >
      36              :         <span>{{ $t('assetBrowser.modelTypeSelectorLabel') }}</span>
      37              :         <AppSingleSelect
      38              :           v-model="modelType"
      39              :           :label="
      40              :             isLoading
      41              :               ? $t('g.loading')
      42              :               : $t('assetBrowser.modelTypeSelectorPlaceholder')
      43              :           "
      44              :           :accessible-label="$t('assetBrowser.modelTypeSelectorLabel')"
      45              :           :options="typeOptions"
      46              :           :disabled="isLoading"
      47              :           data-attr="upload-model-file-type-selector"
      48              :         />
      49              :       </div>
      50              : 
      51              :       <div v-else-if="state.status === 'done'" class="flex flex-col gap-2">
      52              :         <p class="m-0 font-bold text-foreground">
      53              :           {{ $t('assetBrowser.modelUploaded') }}
      54              :         </p>
      55              :         <p class="m-0">
      56              :           {{ $t('assetBrowser.findInLibrary', { type: modelTypeLabel }) }}
      57              :         </p>
      58              :       </div>
      59              : 
      60              :       <p v-if="transferEstimate" class="m-0">{{ transferEstimate }}</p>
      61              :       <p role="status" :class="cn('m-0', !statusLine && 'sr-only')">
      62              :         {{ statusLine }}
      63              :       </p>
      64              :     </div>
      65              : 
      66              :     <div class="flex w-full shrink-0 justify-end gap-2">
      67              :       <Button
      68              :         v-if="canCancel"
      69              :         variant="secondary"
      70              :         size="lg"
      71              :         data-attr="upload-model-file-cancel-button"
      72              :         @click="emit('cancel')"
      73              :       >
      74              :         {{ $t('g.cancel') }}
      75              :       </Button>
      76              :       <Button
      77              :         v-else-if="state.status === 'saving'"
      78              :         variant="secondary"
      79              :         size="lg"
      80              :         data-attr="upload-model-file-close-button"
      81              :         @click="emit('close')"
      82              :       >
      83              :         {{ $t('g.close') }}
      84              :       </Button>
      85              :       <template v-else-if="state.status === 'done'">
      86              :         <Button
      87              :           variant="muted-textonly"
      88              :           size="lg"
      89              :           data-attr="upload-model-file-another-button"
      90              :           @click="emit('back')"
      91              :         >
      92              :           {{ $t('assetBrowser.importAnother') }}
      93              :         </Button>
      94              :         <Button
      95              :           variant="secondary"
      96              :           size="lg"
      97              :           data-attr="upload-model-file-finish-button"
      98              :           @click="emit('close')"
      99              :         >
     100              :           {{ $t('assetBrowser.finish') }}
     101              :         </Button>
     102              :       </template>
     103              :       <template v-else>
     104              :         <Button
     105              :           variant="muted-textonly"
     106              :           size="lg"
     107              :           data-attr="upload-model-file-back-button"
     108              :           @click="emit('back')"
     109              :         >
     110              :           {{ $t('g.back') }}
     111              :         </Button>
     112              :         <Button
     113              :           variant="secondary"
     114              :           size="lg"
     115              :           data-attr="upload-model-file-upload-button"
     116              :           :disabled="!modelType"
     117              :           @click="emit('upload')"
     118              :         >
     119              :           {{
     120              :             state.status === 'failed'
     121              :               ? $t('assetBrowser.fileUpload.tryAgain')
     122              :               : $t('assetBrowser.fileUpload.upload')
     123              :           }}
     124              :         </Button>
     125              :       </template>
     126              :     </div>
     127              :   </div>
     128              : </template>
     129              : 
     130              : <script setup lang="ts">
     131              : import { cn } from '@comfyorg/tailwind-utils'
     132              : import { computed } from 'vue'
     133              : import { useI18n } from 'vue-i18n'
     134              : 
     135              : import AppSingleSelect from '@/components/common/AppSingleSelect.vue'
     136              : import Button from '@comfyorg/design-system/button/Button'
     137              : import { useModelTypes } from '@/platform/assets/composables/useModelTypes'
     138              : import type { ModelFileUpload } from '@/platform/workspace/composables/useUploadModelFile'
     139              : import { formatSize } from '@comfyorg/shared-frontend-utils/formatUtil'
     140              : 
     141              : const { state, folders } = defineProps<{
     142              :   state: Exclude<ModelFileUpload, { status: 'idle' }>
     143              :   folders: readonly string[]
     144              : }>()
     145              : 
     146            0 : const modelType = defineModel<string>({ required: true })
     147              : 
     148            0 : const emit = defineEmits<{
     149              :   upload: []
     150              :   cancel: []
     151              :   back: []
     152              :   close: []
     153              : }>()
     154              : 
     155            0 : const { t, locale } = useI18n()
     156            0 : const { modelTypes, isLoading } = useModelTypes()
     157              : 
     158            0 : const isTransferring = computed(
     159              :   () => state.status === 'uploading' || state.status === 'reconnecting'
     160              : )
     161              : 
     162            0 : const percent = computed(() =>
     163              :   (state.status === 'uploading' || state.status === 'reconnecting') &&
     164              :   state.file.size > 0
     165              :     ? Math.round((state.sent / state.file.size) * 100)
     166              :     : 0
     167              : )
     168              : 
     169            0 : const canCancel = computed(
     170              :   () => isTransferring.value || state.status === 'stopping'
     171              : )
     172              : 
     173            0 : const transferEstimate = computed(() => {
     174            0 :   if (
     175              :     state.status === 'uploading' &&
     176              :     state.bytesPerSecond &&
     177              :     state.bytesPerSecond > 0
     178              :   ) {
     179            0 :     return t('assetBrowser.fileUpload.transferEstimate', {
     180              :       rate: formatSize(Math.max(1, Math.round(state.bytesPerSecond))),
     181              :       time: formatTimeLeft(
     182              :         Math.ceil((state.file.size - state.sent) / state.bytesPerSecond)
     183              :       )
     184              :     })
     185              :   }
     186              :   return undefined
     187              : })
     188              : 
     189            0 : const statusLine = computed(() => {
     190            0 :   if (state.status === 'reconnecting')
     191            0 :     return t('assetBrowser.fileUpload.reconnecting')
     192            0 :   if (state.status === 'saving') return t('assetBrowser.fileUpload.saving')
     193            0 :   if (state.status === 'stopping') return t('assetBrowser.fileUpload.stopping')
     194              :   return undefined
     195              : })
     196              : 
     197            0 : function formatTimeLeft(seconds: number) {
     198              :   const units = [
     199              :     { unit: 'hour', count: Math.floor(seconds / 3600) },
     200              :     { unit: 'minute', count: Math.floor((seconds % 3600) / 60) },
     201              :     { unit: 'second', count: seconds % 60 }
     202              :   ]
     203            0 :   return units
     204              :     .filter(
     205              :       ({ unit, count }) => count > 0 || (unit === 'second' && seconds === 0)
     206              :     )
     207              :     .map(({ unit, count }) =>
     208              :       new Intl.NumberFormat(locale.value, {
     209              :         style: 'unit',
     210              :         unit,
     211              :         unitDisplay: 'narrow'
     212              :       }).format(count)
     213              :     )
     214              :     .join(' ')
     215              : }
     216              : 
     217            0 : const progressAttrs = computed(() =>
     218              :   isTransferring.value
     219              :     ? {
     220              :         role: 'progressbar',
     221              :         'aria-label': title.value,
     222              :         'aria-valuemin': 0,
     223              :         'aria-valuemax': 100,
     224              :         'aria-valuenow': percent.value
     225              :       }
     226              :     : {}
     227              : )
     228              : 
     229            0 : const title = computed(() =>
     230              :   isTransferring.value
     231              :     ? t('assetBrowser.fileUpload.uploading', { name: state.file.name })
     232              :     : state.file.name
     233              : )
     234              : 
     235            0 : const sizeText = computed(() =>
     236              :   state.status === 'uploading' || state.status === 'reconnecting'
     237              :     ? t('assetBrowser.fileUpload.progress', {
     238              :         sent: formatSize(state.sent),
     239              :         total: formatSize(state.file.size)
     240              :       })
     241              :     : formatSize(state.file.size)
     242              : )
     243              : 
     244            0 : const typeOptions = computed(() =>
     245              :   folders.map((value) => ({
     246              :     value,
     247              :     name: modelTypes.value.find((type) => type.value === value)?.name ?? value
     248              :   }))
     249              : )
     250              : 
     251            0 : const modelTypeLabel = computed(() => {
     252            0 :   const folder = state.status === 'done' ? state.modelType : modelType.value
     253            0 :   return (
     254              :     typeOptions.value.find((option) => option.value === folder)?.name ?? folder
     255              :   )
     256              : })
     257              : </script>
        

Generated by: LCOV version 2.0-1