1+ import type { AssetItem } from '@/platform/assets/schemas/assetSchema'
2+ import type { OutputAssetMetadata } from '@/platform/assets/schemas/assetMetadataSchema'
13import type { AssetContext } from '@/platform/assets/schemas/mediaAssetSchema'
4+ import { api } from '@/scripts/api'
5+ import type { ResultItemImpl , TaskItemImpl } from '@/stores/queueStore'
26
37/**
48 * Extract asset type from tags array
@@ -10,3 +14,60 @@ export function getAssetType(tags?: string[]): AssetContext['type'] {
1014 if ( tag === 'output' ) return 'output'
1115 return 'input'
1216}
17+
18+ /**
19+ * Maps a TaskItemImpl output to an AssetItem format
20+ * @param taskItem The task item containing execution data
21+ * @param output The output from the task
22+ * @param useDisplayName Whether to truncate the filename for display
23+ * @returns AssetItem formatted object
24+ */
25+ export function mapTaskOutputToAssetItem (
26+ taskItem : TaskItemImpl ,
27+ output : ResultItemImpl
28+ ) : AssetItem {
29+ const metadata : OutputAssetMetadata = {
30+ promptId : taskItem . promptId ,
31+ nodeId : output . nodeId ,
32+ subfolder : output . subfolder ,
33+ executionTimeInSeconds : taskItem . executionTimeInSeconds ,
34+ format : output . format ,
35+ workflow : taskItem . workflow
36+ }
37+
38+ return {
39+ id : taskItem . promptId ,
40+ name : output . filename ,
41+ size : 0 ,
42+ created_at : taskItem . executionStartTimestamp
43+ ? new Date ( taskItem . executionStartTimestamp ) . toISOString ( )
44+ : new Date ( ) . toISOString ( ) ,
45+ tags : [ 'output' ] ,
46+ preview_url : output . url ,
47+ user_metadata : metadata
48+ }
49+ }
50+
51+ /**
52+ * Maps input directory file to AssetItem format
53+ * @param filename The filename
54+ * @param index File index for unique ID
55+ * @param directory The directory type
56+ * @returns AssetItem formatted object
57+ */
58+ export function mapInputFileToAssetItem (
59+ filename : string ,
60+ index : number ,
61+ directory : 'input' | 'output' = 'input'
62+ ) : AssetItem {
63+ return {
64+ id : `${ directory } -${ index } -${ filename } ` ,
65+ name : filename ,
66+ size : 0 ,
67+ created_at : new Date ( ) . toISOString ( ) ,
68+ tags : [ directory ] ,
69+ preview_url : api . apiURL (
70+ `/view?filename=${ encodeURIComponent ( filename ) } &type=${ directory } `
71+ )
72+ }
73+ }
0 commit comments