Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/platform/assets/services/assetService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,18 @@ describe(assetService.getAssetsPageForNodeType, () => {
})

describe(assetService.getAssetsForNodeType, () => {
it('asks for public models explicitly instead of relying on the server default', async () => {
vi.mocked(api.fetchApi).mockResolvedValueOnce(
buildAssetListResponse([validAsset({ id: 'ckpt-1' })])
)

await assetService.getAssetsForNodeType('CheckpointLoaderSimple')

const requestedUrl = vi.mocked(api.fetchApi).mock.calls[0]?.[0]
const params = new URL(requestedUrl, 'http://localhost').searchParams
expect(params.get('include_public')).toBe('true')
})

it('returns just the assets array from the page response', async () => {
vi.mocked(api.fetchApi).mockResolvedValueOnce(
buildAssetListResponse([validAsset({ id: 'ckpt-1' })], { hasMore: true })
Expand Down
11 changes: 8 additions & 3 deletions src/platform/assets/services/assetService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,17 +620,22 @@ function createAssetService() {
return EMPTY_PAGE
}

// Find the category for this node type using efficient O(1) lookup
const modelToNodeStore = useModelToNodeStore()
const category = modelToNodeStore.getCategoryForNodeType(nodeType)

if (!category) {
return EMPTY_PAGE
}

// Fetch assets for this category using same API pattern as getAssetModels
return await handleAssetRequest(
{ includeTags: [MODELS_TAG, category], limit, offset, after, signal },
{
includeTags: [MODELS_TAG, category],
limit,
offset,
after,
includePublic: true,
signal
},
`assets for ${nodeType}`
)
}
Expand Down
14 changes: 14 additions & 0 deletions src/platform/assets/utils/assetPreviewUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ describe('findOutputAsset', () => {
expect(result).toEqual(localAsset)
})

it("only searches the user's own assets, never the public catalog", async () => {
mockFetchEmpty()
mockFetchEmpty()

await findOutputAsset('ComfyUI_00081_.glb')

const includePublic = vi
.mocked(api.fetchApi)
.mock.calls.map(([url]) =>
new URL(url, 'http://localhost').searchParams.get('include_public')
)
expect(includePublic).toEqual(['false', 'false'])
})

it('returns undefined when no asset matches', async () => {
mockFetchEmpty()
mockFetchEmpty()
Expand Down
8 changes: 4 additions & 4 deletions src/platform/assets/utils/assetPreviewUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export function isAssetPreviewSupported(): boolean {
return useFeatureFlags().flags.assetsEnabled
}

async function fetchAssets(
async function fetchOwnAssets(
params: Record<string, string>
): Promise<AssetRecord[]> {
const query = new URLSearchParams(params)
const query = new URLSearchParams({ ...params, include_public: 'false' })
const res = await api.fetchApi(`/assets?${query}`)
if (!res.ok) return []
const data = await res.json()
Expand All @@ -46,11 +46,11 @@ export function resolvePreviewUrl(asset: AssetRecord): string {
export async function findOutputAsset(
name: string
): Promise<AssetRecord | undefined> {
const byHash = await fetchAssets({ hash: name })
const byHash = await fetchOwnAssets({ hash: name })
const hashMatch = byHash.find((a) => a.hash === name)
if (hashMatch) return hashMatch

const byName = await fetchAssets({ name_contains: name })
const byName = await fetchOwnAssets({ name_contains: name })
return byName.find((a) => a.name === name)
}

Expand Down
Loading