mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-26 19:09:52 +00:00
Enable ts-strict for modelStore.ts (#1241)
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
// @ts-strict-ignore
|
||||
import { api } from '@/scripts/api'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
@@ -54,7 +53,8 @@ export class ComfyModelDef {
|
||||
|
||||
constructor(name: string, directory: string) {
|
||||
this.file_name = name
|
||||
this.simplified_file_name = name.replaceAll('\\', '/').split('/').pop()
|
||||
this.simplified_file_name =
|
||||
name.replaceAll('\\', '/').split('/').pop() ?? ''
|
||||
if (this.simplified_file_name.endsWith('.safetensors')) {
|
||||
this.simplified_file_name = this.simplified_file_name.slice(
|
||||
0,
|
||||
@@ -156,12 +156,12 @@ const folderBlacklist = ['configs', 'custom_nodes']
|
||||
/** Model store handler, wraps individual per-folder model stores */
|
||||
export const useModelStore = defineStore('modelStore', {
|
||||
state: () => ({
|
||||
modelStoreMap: {} as Record<string, ModelStore>,
|
||||
isLoading: {} as Record<string, Promise<ModelStore>>,
|
||||
modelStoreMap: {} as Record<string, ModelStore | null>,
|
||||
isLoading: {} as Record<string, Promise<ModelStore | null> | null>,
|
||||
modelFolders: [] as string[]
|
||||
}),
|
||||
actions: {
|
||||
async getModelsInFolderCached(folder: string): Promise<ModelStore> {
|
||||
async getModelsInFolderCached(folder: string): Promise<ModelStore | null> {
|
||||
if (folder in this.modelStoreMap) {
|
||||
return this.modelStoreMap[folder]
|
||||
}
|
||||
@@ -174,7 +174,7 @@ export const useModelStore = defineStore('modelStore', {
|
||||
}
|
||||
const store = new ModelStore(folder, models)
|
||||
this.modelStoreMap[folder] = store
|
||||
this.isLoading[folder] = false
|
||||
this.isLoading[folder] = null
|
||||
return store
|
||||
})
|
||||
this.isLoading[folder] = promise
|
||||
|
||||
@@ -46,12 +46,15 @@ describe('useModelStore', () => {
|
||||
enableMocks()
|
||||
const folderStore = await store.getModelsInFolderCached('checkpoints')
|
||||
expect(folderStore).not.toBeNull()
|
||||
expect(Object.keys(folderStore.models)).toHaveLength(3)
|
||||
if (!folderStore) return
|
||||
expect(Object.keys(folderStore.models).length).toBe(3)
|
||||
})
|
||||
|
||||
it('should load model metadata', async () => {
|
||||
enableMocks()
|
||||
const folderStore = await store.getModelsInFolderCached('checkpoints')
|
||||
expect(folderStore).not.toBeNull()
|
||||
if (!folderStore) return
|
||||
const model = folderStore.models['sdxl.safetensors']
|
||||
await model.load()
|
||||
expect(model.title).toBe('Title of sdxl.safetensors')
|
||||
@@ -67,6 +70,8 @@ describe('useModelStore', () => {
|
||||
it('should handle no metadata', async () => {
|
||||
enableMocks()
|
||||
const folderStore = await store.getModelsInFolderCached('checkpoints')
|
||||
expect(folderStore).not.toBeNull()
|
||||
if (!folderStore) return
|
||||
const model = folderStore.models['noinfo.safetensors']
|
||||
await model.load()
|
||||
expect(model.file_name).toBe('noinfo.safetensors')
|
||||
|
||||
Reference in New Issue
Block a user