@@ -249,30 +249,39 @@ export async function listDownloadableArtifacts(
249249 const artifacts : DaemonArtifactInventoryEntry [ ] = [ ] ;
250250 for ( const [ id , entry ] of pendingArtifacts ( ) ) {
251251 if ( ! canReadArtifact ( entry , tenantId ) ) continue ;
252- let stat : fs . Stats ;
253- try {
254- stat = await fs . promises . stat ( entry . artifactPath ) ;
255- } catch {
256- cleanupDownloadableArtifact ( id ) ;
257- continue ;
258- }
259- const listing = describeArtifactForInventory ( id , entry , stat ) ;
260- if ( ! listing || entry . cleanupRequested ) continue ;
261- artifacts . push ( {
262- id,
263- ...( entry . artifactType !== undefined ? { artifactType : entry . artifactType } : { } ) ,
264- filename : listing . fileName ,
265- mimeType : listing . mimeType ,
266- ...( listing . sizeBytes !== undefined ? { sizeBytes : listing . sizeBytes } : { } ) ,
267- createdAt : new Date ( entry . createdAt ) . toISOString ( ) ,
268- expiresAt : new Date ( entry . createdAt + ARTIFACT_CLEANUP_TIMEOUT_MS ) . toISOString ( ) ,
269- ...( entry . displayRotation !== undefined ? { displayRotation : entry . displayRotation } : { } ) ,
270- ...( entry . sessionName !== undefined ? { sessionName : entry . sessionName } : { } ) ,
271- } ) ;
252+ const listed = await readInventoryEntry ( id , entry ) ;
253+ if ( listed ) artifacts . push ( listed ) ;
272254 }
273255 return artifacts ;
274256}
275257
258+ /** One entry's inventory row, or undefined when its source is gone or it is being cleaned up. */
259+ async function readInventoryEntry (
260+ id : string ,
261+ entry : ArtifactEntry ,
262+ ) : Promise < DaemonArtifactInventoryEntry | undefined > {
263+ let stat : fs . Stats ;
264+ try {
265+ stat = await fs . promises . stat ( entry . artifactPath ) ;
266+ } catch {
267+ cleanupDownloadableArtifact ( id ) ;
268+ return undefined ;
269+ }
270+ const listing = describeArtifactForInventory ( id , entry , stat ) ;
271+ if ( ! listing || entry . cleanupRequested ) return undefined ;
272+ return {
273+ id,
274+ ...( entry . artifactType !== undefined ? { artifactType : entry . artifactType } : { } ) ,
275+ filename : listing . fileName ,
276+ mimeType : listing . mimeType ,
277+ ...( listing . sizeBytes !== undefined ? { sizeBytes : listing . sizeBytes } : { } ) ,
278+ createdAt : new Date ( entry . createdAt ) . toISOString ( ) ,
279+ expiresAt : new Date ( entry . createdAt + ARTIFACT_CLEANUP_TIMEOUT_MS ) . toISOString ( ) ,
280+ ...( entry . displayRotation !== undefined ? { displayRotation : entry . displayRotation } : { } ) ,
281+ ...( entry . sessionName !== undefined ? { sessionName : entry . sessionName } : { } ) ,
282+ } ;
283+ }
284+
276285/**
277286 * What an inventory reports without preparing a payload. A directory is archived only on its first
278287 * download, so its size is known only after that archive exists.
0 commit comments