11import { readFile } from 'node:fs/promises'
22import path from 'node:path'
3+ import type { FailedAttempt } from '@filoz/synapse-sdk'
34import { Synapse } from '@filoz/synapse-sdk'
45import { z } from 'incur'
56import { privateKeyClient } from '../client.ts'
@@ -32,6 +33,8 @@ export const uploadCommand = {
3233 pieceCid : z . string ( ) ,
3334 pieceScannerUrl : z . string ( ) ,
3435 size : z . number ( ) ,
36+ requestedCopies : z . number ( ) ,
37+ complete : z . boolean ( ) ,
3538 copyResults : z . array (
3639 z . object ( {
3740 dataSetId : z . string ( ) ,
@@ -122,18 +125,20 @@ export const uploadCommand = {
122125 providerRole : copy . role ,
123126 } ) )
124127 const copyFailures = result . failedAttempts . map ( ( failure : any ) => ( {
125- providerId : failure . providerId ,
128+ providerId : failure . providerId . toString ( ) ,
126129 role : failure . role ,
127- error : failure instanceof Error ? failure . message : String ( failure ) ,
128- explicit : failure . explicit ,
130+ error : formatFailedAttemptError ( failure ) ,
131+ explicit : Boolean ( failure . explicit ) ,
129132 } ) )
130133
131134 return out . done ( {
132- status : 'uploaded' ,
135+ status : result . complete ? 'uploaded' : 'partially_uploaded ',
133136 result : {
134137 pieceCid : cidStr ,
135138 pieceScannerUrl : pieceScannerUrl ( cidStr , chain ) ,
136139 size : result . size ,
140+ requestedCopies : result . requestedCopies ,
141+ complete : result . complete ,
137142 copyResults,
138143 copyFailures,
139144 } ,
@@ -144,3 +149,13 @@ export const uploadCommand = {
144149 }
145150 } ,
146151}
152+
153+ function formatFailedAttemptError ( failure : FailedAttempt | Error | unknown ) {
154+ if ( failure instanceof Error ) return failure . message
155+ if ( failure && typeof failure === 'object' && 'error' in failure ) {
156+ const error = failure . error
157+ if ( error instanceof Error ) return error . message
158+ if ( error !== undefined && error !== null ) return String ( error )
159+ }
160+ return String ( failure )
161+ }
0 commit comments