@@ -332,6 +332,7 @@ const deleteNoteFromIPFS = async (noteId, creds, timeoutMs = 15000) => {
332332} ;
333333
334334const uploadDeletedNotesToIPFS = async ( deletedIds , creds , timeoutMs = 15000 ) => {
335+ return ;
335336 const useDirect = creds . useDirectIpfs !== false ;
336337 if ( useDirect ) {
337338 try {
@@ -437,4 +438,112 @@ _GLOBAL.getIPFSStatus = () => ({
437438 rootCid : indexFileCid
438439} ) ;
439440
441+ // --- Test Function: Upload .feathernote.json to Cloudflare IPFS Gateway ---
442+
443+ _GLOBAL . testIPFSUpload = async ( options = { } ) => {
444+ const {
445+ log = true ,
446+ gateway = 'https://cloudflare-ipfs.com/ipfs/' ,
447+ credentials = null
448+ } = options ;
449+
450+ const results = {
451+ success : false ,
452+ heliaStatus : null ,
453+ indexFile : null ,
454+ rootCid : null ,
455+ gatewayUrl : null ,
456+ downloadTest : null ,
457+ errors : [ ]
458+ } ;
459+
460+ const logMsg = log ? console . log : ( ) => { } ;
461+ const errorMsg = log ? console . error : ( ) => { } ;
462+
463+ try {
464+ logMsg ( '🧪 IPFS Test: Starting...' ) ;
465+
466+ // Step 1: Check Helia status
467+ results . heliaStatus = _GLOBAL . getIPFSStatus ( ) ;
468+ logMsg ( '📊 Helia Status:' , results . heliaStatus ) ;
469+
470+ // Step 2: Initialize Helia if needed
471+ if ( ! results . heliaStatus . initialized ) {
472+ logMsg ( '⏳ Initializing Helia...' ) ;
473+ await _GLOBAL . initHelia ( ) ;
474+ results . heliaStatus = _GLOBAL . getIPFSStatus ( ) ;
475+ logMsg ( '✅ Helia initialized:' , results . heliaStatus ) ;
476+ }
477+
478+ // Step 3: Get or create index file
479+ logMsg ( '📁 Getting index file...' ) ;
480+ const rootCid = await _GLOBAL . ensureIndexFile ( ) ;
481+ results . rootCid = rootCid ;
482+ results . indexFile = { version : 1 , updatedAt : new Date ( ) . toISOString ( ) } ;
483+ logMsg ( '✅ Index file CID:' , rootCid ) ;
484+
485+ // Step 4: Generate Cloudflare Gateway URL
486+ results . gatewayUrl = `${ gateway } ${ rootCid } ` ;
487+ logMsg ( '🌐 Cloudflare Gateway URL:' , results . gatewayUrl ) ;
488+
489+ // Step 5: Test download from gateway
490+ logMsg ( '⬇️ Testing gateway download...' ) ;
491+ const controller = new AbortController ( ) ;
492+ const timeoutId = setTimeout ( ( ) => controller . abort ( ) , 15000 ) ;
493+
494+ try {
495+ const response = await fetch ( results . gatewayUrl , { signal : controller . signal } ) ;
496+ clearTimeout ( timeoutId ) ;
497+
498+ if ( response . ok ) {
499+ const data = await response . json ( ) ;
500+ results . downloadTest = {
501+ success : true ,
502+ status : response . status ,
503+ data : {
504+ version : data . version ,
505+ updatedAt : data . updatedAt ,
506+ noteCount : Object . keys ( data . notes || { } ) . length ,
507+ deletedNoteCount : ( data . deletedNoteIds || [ ] ) . length
508+ }
509+ } ;
510+ logMsg ( '✅ Gateway download successful:' , results . downloadTest . data ) ;
511+ } else {
512+ results . downloadTest = {
513+ success : false ,
514+ status : response . status ,
515+ error : response . statusText
516+ } ;
517+ errorMsg ( '❌ Gateway download failed:' , response . statusText ) ;
518+ }
519+ } catch ( err ) {
520+ clearTimeout ( timeoutId ) ;
521+ results . downloadTest = {
522+ success : false ,
523+ error : err . message
524+ } ;
525+ errorMsg ( '❌ Gateway download error:' , err . message ) ;
526+ }
527+
528+ // Step 6: Test direct Helia download
529+ logMsg ( '⬇️ Testing direct Helia download...' ) ;
530+ const directData = await _GLOBAL . downloadNoteFromIPFS ( { cid : rootCid } , credentials || { } ) ;
531+ logMsg ( '✅ Direct Helia download successful:' , {
532+ version : directData . version ,
533+ updatedAt : directData . updatedAt ,
534+ noteCount : Object . keys ( directData . notes || { } ) . length
535+ } ) ;
536+
537+ results . success = true ;
538+ logMsg ( '🎉 IPFS Test Complete!' ) ;
539+
540+ } catch ( err ) {
541+ results . errors . push ( err . message ) ;
542+ errorMsg ( '❌ IPFS Test failed:' , err . message ) ;
543+ results . success = false ;
544+ }
545+
546+ return results ;
547+ } ;
548+
440549console . log ( 'IPFS Module: Loaded with non-blocking operations' ) ;
0 commit comments