@@ -29,10 +29,15 @@ export async function ipfsAddFromFs(
2929 let totalSize = 0 ;
3030 if ( fs . statSync ( dirOrFilePath ) . isDirectory ( ) ) {
3131 for ( const filePath of getStatFiles ( dirOrFilePath ) ) {
32- totalSize += fs . statSync ( filePath ) . size ;
32+ const size = fs . statSync ( filePath ) . size ;
33+ totalSize += size ;
34+ console . log ( `[IPFS-UPLOAD] File: ${ filePath } , Size: ${ size } ` ) ;
3335 }
3436 } else {
3537 totalSize = fs . statSync ( dirOrFilePath ) . size ;
38+ console . log (
39+ `[IPFS-UPLOAD] Single file: ${ dirOrFilePath } , Size: ${ totalSize } `
40+ ) ;
3641 }
3742 // Helper to recursively collect files from a directory
3843 function * getFiles (
@@ -66,16 +71,24 @@ export async function ipfsAddFromFs(
6671 // Add files to IPFS
6772 let lastCid = "" ;
6873 let uploaded = 0 ;
74+ console . log ( `[IPFS-UPLOAD] Starting upload. Total size: ${ totalSize } ` ) ;
6975 for await ( const result of kuboClient . addAll ( files , {
70- wrapWithDirectory : true ,
71- progress : ( bytes : number ) => {
72- uploaded = bytes ;
73- if ( onProgress && totalSize > 0 ) {
74- onProgress ( Math . min ( uploaded / totalSize , 1 ) ) ;
75- }
76- }
76+ wrapWithDirectory : true
7777 } ) ) {
7878 lastCid = result . cid . toString ( ) ;
79+ uploaded += result . size || 0 ;
80+ const percent = totalSize > 0 ? Math . min ( uploaded / totalSize , 1 ) : 0 ;
81+ console . log (
82+ `[IPFS-UPLOAD] Uploaded chunk. CID: ${ lastCid } , Path: ${ result . path } , Size: ${ result . size } `
83+ ) ;
84+ console . log (
85+ `[IPFS-UPLOAD] Progress: ${ uploaded } bytes uploaded (${ (
86+ percent * 100
87+ ) . toFixed ( 2 ) } %)`
88+ ) ;
89+ if ( onProgress && totalSize > 0 ) {
90+ onProgress ( percent ) ;
91+ }
7992 }
8093 if ( ! lastCid ) throw Error ( "No CID returned from IPFS add" ) ;
8194 return `/ipfs/${ lastCid } ` ;
0 commit comments