fix: update asset metadata to use correct user_metadata fields

Amp-Thread-ID: https://ampcode.com/threads/T-019bc5e5-232c-72bc-893a-afda46003fd3
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Alexander Brown
2026-01-16 00:42:53 -08:00
parent 19f18ed151
commit 09dd3f1a2c
4 changed files with 30 additions and 12 deletions

View File

@@ -127,6 +127,7 @@ import { useFeatureFlags } from '@/composables/useFeatureFlags'
import AssetBadgeGroup from '@/platform/assets/components/AssetBadgeGroup.vue'
import type { AssetDisplayItem } from '@/platform/assets/composables/useAssetBrowser'
import { assetService } from '@/platform/assets/services/assetService'
import { getAssetDisplayName } from '@/platform/assets/utils/assetMetadataUtils'
import { useSettingStore } from '@/platform/settings/settingStore'
import { useToastStore } from '@/platform/updates/common/toastStore'
import { useDialogStore } from '@/stores/dialogStore'
@@ -181,7 +182,9 @@ const descId = useId()
const isEditing = ref(false)
const newNameRef = ref<string>()
const displayName = computed(() => newNameRef.value ?? asset.name)
const displayName = computed(
() => newNameRef.value ?? getAssetDisplayName(asset)
)
const showAssetOptions = computed(
() =>
@@ -260,10 +263,10 @@ async function assetRename(newName?: string) {
newNameRef.value = newName
try {
const result = await assetService.updateAsset(asset.id, {
name: newName
user_metadata: { name: newName }
})
// Update with the actual name once the server responds
newNameRef.value = result.name
newNameRef.value = getAssetDisplayName(result)
} catch (err: unknown) {
console.error(err)
toastStore.add({

View File

@@ -90,6 +90,11 @@ export type AsyncUploadResponse = z.infer<typeof zAsyncUploadResponse>
export type ModelFolder = z.infer<typeof zModelFolder>
export type ModelFile = z.infer<typeof zModelFile>
/** Payload for updating an asset via PUT /assets/:id */
export type AssetUpdatePayload = Partial<
Pick<AssetItem, 'name' | 'tags' | 'user_metadata'>
>
// Legacy interface for backward compatibility (now aligned with Zod schema)
export interface ModelFolderInfo {
name: string

View File

@@ -10,6 +10,7 @@ import type {
AssetItem,
AssetMetadata,
AssetResponse,
AssetUpdatePayload,
AsyncUploadResponse,
ModelFile,
ModelFolder
@@ -298,7 +299,7 @@ function createAssetService() {
*/
async function updateAsset(
id: string,
newData: Partial<AssetMetadata>
newData: AssetUpdatePayload
): Promise<AssetItem> {
const res = await api.fetchApi(`${ASSETS_ENDPOINT}/${id}`, {
method: 'PUT',

View File

@@ -32,20 +32,29 @@ export function getAssetBaseModel(asset: AssetItem): string | null {
* @returns The display name or filename
*/
export function getAssetDisplayName(asset: AssetItem): string {
return typeof asset.user_metadata?.display_name === 'string'
? asset.user_metadata.display_name
return typeof asset.user_metadata?.name === 'string'
? asset.user_metadata.name
: asset.name
}
/**
* Safely extracts source URL from asset metadata
* Constructs source URL from asset's source_arn
* @param asset - The asset to extract source URL from
* @returns The source URL or null if not present
* @returns The source URL or null if not present/parseable
*/
export function getAssetSourceUrl(asset: AssetItem): string | null {
return typeof asset.user_metadata?.source_url === 'string'
? asset.user_metadata.source_url
: null
const sourceArn = asset.user_metadata?.source_arn
if (typeof sourceArn !== 'string') return null
const civitaiMatch = sourceArn.match(
/^civitai:model:(\d+):version:(\d+)(?::file:\d+)?$/
)
if (civitaiMatch) {
const [, modelId, versionId] = civitaiMatch
return `https://civitai.com/models/${modelId}?modelVersionId=${versionId}`
}
return null
}
/**
@@ -54,7 +63,7 @@ export function getAssetSourceUrl(asset: AssetItem): string | null {
* @returns Array of trigger phrases
*/
export function getAssetTriggerPhrases(asset: AssetItem): string[] {
const phrases = asset.user_metadata?.trigger_phrases
const phrases = asset.user_metadata?.trained_words
if (Array.isArray(phrases)) {
return phrases.filter((p): p is string => typeof p === 'string')
}