mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 02:32:18 +00:00
[backport cloud/1.37] feat: add getAssetFilename util with fallback chain (#8310)
Backport of #8309 to `cloud/1.37` Automatically created by backport workflow. Co-authored-by: Alexander Brown <drjkl@comfy.org> Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -149,3 +149,13 @@ export function getAssetUserDescription(asset: AssetItem): string {
|
|||||||
? asset.user_metadata.user_description
|
? asset.user_metadata.user_description
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the filename for an asset with fallback chain
|
||||||
|
* Checks user_metadata.filename first, then metadata.filename, then asset.name
|
||||||
|
* @param asset - The asset to extract filename from
|
||||||
|
* @returns The filename string
|
||||||
|
*/
|
||||||
|
export function getAssetFilename(asset: AssetItem): string {
|
||||||
|
return getStringProperty(asset, 'filename') ?? asset.name
|
||||||
|
}
|
||||||
|
|||||||
@@ -282,16 +282,6 @@ describe('createModelNodeFromAsset', () => {
|
|||||||
expectedCode: 'INVALID_ASSET' as const,
|
expectedCode: 'INVALID_ASSET' as const,
|
||||||
errorPattern: /Invalid filename.*expected non-empty string/
|
errorPattern: /Invalid filename.*expected non-empty string/
|
||||||
},
|
},
|
||||||
{
|
|
||||||
case: 'non-string filename',
|
|
||||||
overrides: {
|
|
||||||
user_metadata: { filename: 123 },
|
|
||||||
metadata: undefined,
|
|
||||||
name: ''
|
|
||||||
},
|
|
||||||
expectedCode: 'INVALID_ASSET' as const,
|
|
||||||
errorPattern: /Invalid filename.*expected non-empty string, got number/
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
case: 'empty filename with no fallback',
|
case: 'empty filename with no fallback',
|
||||||
overrides: {
|
overrides: {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
MISSING_TAG,
|
MISSING_TAG,
|
||||||
MODELS_TAG
|
MODELS_TAG
|
||||||
} from '@/platform/assets/services/assetService'
|
} from '@/platform/assets/services/assetService'
|
||||||
|
import { getAssetFilename } from '@/platform/assets/utils/assetMetadataUtils'
|
||||||
import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
|
import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
|
||||||
import { app } from '@/scripts/app'
|
import { app } from '@/scripts/app'
|
||||||
import { useLitegraphService } from '@/services/litegraphService'
|
import { useLitegraphService } from '@/services/litegraphService'
|
||||||
@@ -69,11 +70,8 @@ export function createModelNodeFromAsset(
|
|||||||
|
|
||||||
const validAsset = validatedAsset.data
|
const validAsset = validatedAsset.data
|
||||||
|
|
||||||
const userMetadata = validAsset.user_metadata ?? {}
|
const filename = getAssetFilename(validAsset)
|
||||||
|
if (filename.length === 0) {
|
||||||
const filename =
|
|
||||||
userMetadata.filename || validAsset.metadata?.filename || validAsset.name
|
|
||||||
if (typeof filename !== 'string' || filename.length === 0) {
|
|
||||||
console.error(
|
console.error(
|
||||||
`Asset ${validAsset.id} has invalid user_metadata.filename (expected non-empty string, got ${typeof filename})`
|
`Asset ${validAsset.id} has invalid user_metadata.filename (expected non-empty string, got ${typeof filename})`
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
assetFilenameSchema,
|
assetFilenameSchema,
|
||||||
assetItemSchema
|
assetItemSchema
|
||||||
} from '@/platform/assets/schemas/assetSchema'
|
} from '@/platform/assets/schemas/assetSchema'
|
||||||
|
import { getAssetFilename } from '@/platform/assets/utils/assetMetadataUtils'
|
||||||
import { assetService } from '@/platform/assets/services/assetService'
|
import { assetService } from '@/platform/assets/services/assetService'
|
||||||
import { isCloud } from '@/platform/distribution/types'
|
import { isCloud } from '@/platform/distribution/types'
|
||||||
import { useSettingStore } from '@/platform/settings/settingStore'
|
import { useSettingStore } from '@/platform/settings/settingStore'
|
||||||
@@ -115,7 +116,7 @@ const createAssetBrowserWidget = (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const filename = validatedAsset.data.user_metadata?.filename
|
const filename = getAssetFilename(validatedAsset.data)
|
||||||
const validatedFilename = assetFilenameSchema.safeParse(filename)
|
const validatedFilename = assetFilenameSchema.safeParse(filename)
|
||||||
|
|
||||||
if (!validatedFilename.success) {
|
if (!validatedFilename.success) {
|
||||||
|
|||||||
Reference in New Issue
Block a user