peerpigeon 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -217,6 +217,9 @@ export class PeerPigeonUI {
217
217
  // DHT controls
218
218
  this.setupDHTControls();
219
219
 
220
+ // Storage controls
221
+ this.setupStorageControls();
222
+
220
223
  // Crypto controls
221
224
  this.setupCryptoControls();
222
225
 
@@ -232,6 +235,7 @@ export class PeerPigeonUI {
232
235
  const dhtKey = document.getElementById('dht-key');
233
236
  const dhtValue = document.getElementById('dht-value');
234
237
  const dhtGetKey = document.getElementById('dht-get-key'); // Separate key field for retrieval
238
+ const dhtSubscribeKey = document.getElementById('dht-subscribe-key'); // Separate key field for subscription
235
239
  const dhtPutBtn = document.getElementById('dht-put-btn');
236
240
  const dhtUpdateBtn = document.getElementById('dht-update-btn');
237
241
  const dhtGetBtn = document.getElementById('dht-get-btn');
@@ -246,6 +250,7 @@ export class PeerPigeonUI {
246
250
  dhtKey: !!dhtKey,
247
251
  dhtValue: !!dhtValue,
248
252
  dhtGetKey: !!dhtGetKey,
253
+ dhtSubscribeKey: !!dhtSubscribeKey,
249
254
  dhtPutBtn: !!dhtPutBtn,
250
255
  dhtUpdateBtn: !!dhtUpdateBtn,
251
256
  dhtGetBtn: !!dhtGetBtn,
@@ -457,13 +462,11 @@ export class PeerPigeonUI {
457
462
  // Subscribe to DHT key
458
463
  if (dhtSubscribeBtn) {
459
464
  dhtSubscribeBtn.addEventListener('click', async () => {
460
- // Check both key fields - use whichever has a value
461
- const putKey = dhtKey?.value?.trim();
462
- const getKey = dhtGetKey?.value?.trim();
463
- const key = putKey || getKey;
465
+ // Use the dedicated subscription key field
466
+ const key = dhtSubscribeKey?.value?.trim();
464
467
 
465
468
  if (!key) {
466
- this.addDHTLogEntry('❌ Error: Key is required (enter key in either Put/Update or Get field)');
469
+ this.addDHTLogEntry('❌ Error: Key is required for subscription');
467
470
  return;
468
471
  }
469
472
 
@@ -480,12 +483,14 @@ export class PeerPigeonUI {
480
483
  this.addDHTLogEntry(`✅ Subscribed to: ${key}`);
481
484
  if (value !== null) {
482
485
  this.addDHTLogEntry(` Current value from original storing peers: ${JSON.stringify(value)}`);
483
- if (dhtValue) {
484
- dhtValue.value = typeof value === 'string' ? value : JSON.stringify(value);
485
- }
486
486
  } else {
487
487
  this.addDHTLogEntry(' No current value found on original storing peers');
488
488
  }
489
+
490
+ // Clear the subscription key field after successful subscription
491
+ if (dhtSubscribeKey) {
492
+ dhtSubscribeKey.value = '';
493
+ }
489
494
  } catch (error) {
490
495
  this.addDHTLogEntry(`❌ Error subscribing to ${key}: ${error.message}`);
491
496
  }
@@ -495,13 +500,11 @@ export class PeerPigeonUI {
495
500
  // Unsubscribe from DHT key
496
501
  if (dhtUnsubscribeBtn) {
497
502
  dhtUnsubscribeBtn.addEventListener('click', async () => {
498
- // Check both key fields - use whichever has a value
499
- const putKey = dhtKey?.value?.trim();
500
- const getKey = dhtGetKey?.value?.trim();
501
- const key = putKey || getKey;
503
+ // Use the dedicated subscription key field
504
+ const key = dhtSubscribeKey?.value?.trim();
502
505
 
503
506
  if (!key) {
504
- this.addDHTLogEntry('❌ Error: Key is required (enter key in either Put/Update or Get field)');
507
+ this.addDHTLogEntry('❌ Error: Key is required for unsubscription');
505
508
  return;
506
509
  }
507
510
 
@@ -513,6 +516,11 @@ export class PeerPigeonUI {
513
516
  try {
514
517
  await this.mesh.dhtUnsubscribe(key);
515
518
  this.addDHTLogEntry(`🔕 Unsubscribed from: ${key}`);
519
+
520
+ // Clear the subscription key field after successful unsubscription
521
+ if (dhtSubscribeKey) {
522
+ dhtSubscribeKey.value = '';
523
+ }
516
524
  } catch (error) {
517
525
  this.addDHTLogEntry(`❌ Error unsubscribing from ${key}: ${error.message}`);
518
526
  }
@@ -520,6 +528,513 @@ export class PeerPigeonUI {
520
528
  }
521
529
  }
522
530
 
531
+ setupStorageControls() {
532
+ // Ensure storage section starts collapsed with robust hiding
533
+ const storageSection = document.querySelector('.storage');
534
+ const storageToggle = document.getElementById('storage-toggle');
535
+ const storageContent = document.getElementById('storage-content');
536
+
537
+ if (storageSection && storageToggle && storageContent) {
538
+ // Force initial collapsed state with multiple approaches
539
+ storageSection.setAttribute('aria-expanded', 'false');
540
+ storageToggle.setAttribute('aria-expanded', 'false');
541
+
542
+ // Use multiple ways to hide the content
543
+ storageContent.style.display = 'none';
544
+ storageContent.style.visibility = 'hidden';
545
+ storageContent.style.maxHeight = '0';
546
+ storageContent.style.overflow = 'hidden';
547
+ storageContent.classList.add('collapsed');
548
+
549
+ // Ensure the toggle button shows collapsed state
550
+ if (storageToggle.textContent && !storageToggle.textContent.includes('▶')) {
551
+ storageToggle.textContent = storageToggle.textContent.replace('▼', '▶');
552
+ }
553
+ }
554
+
555
+ // Enable/Disable Storage
556
+ const storageEnableBtn = document.getElementById('storage-enable-btn');
557
+ const storageDisableBtn = document.getElementById('storage-disable-btn');
558
+ const storageClearBtn = document.getElementById('storage-clear-btn');
559
+
560
+ if (storageEnableBtn) {
561
+ storageEnableBtn.addEventListener('click', async () => {
562
+ try {
563
+ if (!this.mesh.distributedStorage) {
564
+ this.addStorageLogEntry('❌ Error: Distributed storage not available');
565
+ return;
566
+ }
567
+
568
+ await this.mesh.distributedStorage.enable();
569
+ this.addStorageLogEntry('✅ Distributed storage enabled');
570
+ this.updateStorageStatus();
571
+ } catch (error) {
572
+ this.addStorageLogEntry(`❌ Error enabling storage: ${error.message}`);
573
+ }
574
+ });
575
+ }
576
+
577
+ if (storageDisableBtn) {
578
+ storageDisableBtn.addEventListener('click', async () => {
579
+ try {
580
+ if (!this.mesh.distributedStorage) {
581
+ this.addStorageLogEntry('❌ Error: Distributed storage not available');
582
+ return;
583
+ }
584
+
585
+ await this.mesh.distributedStorage.disable();
586
+ this.addStorageLogEntry('⚠️ Distributed storage disabled');
587
+ this.updateStorageStatus();
588
+ } catch (error) {
589
+ this.addStorageLogEntry(`❌ Error disabling storage: ${error.message}`);
590
+ }
591
+ });
592
+ }
593
+
594
+ if (storageClearBtn) {
595
+ storageClearBtn.addEventListener('click', async () => {
596
+ if (!confirm('Are you sure you want to clear all stored data? This cannot be undone.')) {
597
+ return;
598
+ }
599
+
600
+ try {
601
+ if (!this.mesh.distributedStorage) {
602
+ this.addStorageLogEntry('❌ Error: Distributed storage not available');
603
+ return;
604
+ }
605
+
606
+ await this.mesh.distributedStorage.clear();
607
+ this.addStorageLogEntry('🗑️ All stored data cleared');
608
+ this.updateStorageStatus();
609
+ } catch (error) {
610
+ this.addStorageLogEntry(`❌ Error clearing storage: ${error.message}`);
611
+ }
612
+ });
613
+ }
614
+
615
+ // Store Data
616
+ const storageStoreBtn = document.getElementById('storage-store-btn');
617
+ const storageUpdateBtn = document.getElementById('storage-update-btn');
618
+
619
+ if (storageStoreBtn) {
620
+ storageStoreBtn.addEventListener('click', async () => {
621
+ await this.handleStorageStore(false);
622
+ });
623
+ }
624
+
625
+ if (storageUpdateBtn) {
626
+ storageUpdateBtn.addEventListener('click', async () => {
627
+ await this.handleStorageStore(true);
628
+ });
629
+ }
630
+
631
+ // Retrieve Data
632
+ const storageGetBtn = document.getElementById('storage-get-btn');
633
+ const storageDeleteBtn = document.getElementById('storage-delete-btn');
634
+
635
+ if (storageGetBtn) {
636
+ storageGetBtn.addEventListener('click', async () => {
637
+ const key = document.getElementById('storage-get-key')?.value?.trim();
638
+
639
+ if (!key) {
640
+ this.addStorageLogEntry('❌ Error: Key is required');
641
+ return;
642
+ }
643
+
644
+ try {
645
+ if (!this.mesh.distributedStorage) {
646
+ this.addStorageLogEntry('❌ Error: Distributed storage not available');
647
+ return;
648
+ }
649
+
650
+ const result = await this.mesh.distributedStorage.retrieve(key);
651
+ if (result !== null) {
652
+ this.addStorageLogEntry(`📋 Retrieved: ${key} = ${JSON.stringify(result)}`);
653
+
654
+ // Get key info for metadata display
655
+ try {
656
+ const keyInfo = await this.mesh.distributedStorage.getKeyInfo(key);
657
+ if (keyInfo) {
658
+ this.addStorageLogEntry(` Metadata: public=${keyInfo.isPublic}, immutable=${keyInfo.isImmutable}, owner=${keyInfo.owner?.substring(0, 8)}...`);
659
+ this.addStorageLogEntry(` Created: ${new Date(keyInfo.createdAt).toLocaleString()}`);
660
+ }
661
+ } catch (metaError) {
662
+ // Metadata display is optional, don't fail the retrieval
663
+ console.warn('Could not get metadata for display:', metaError);
664
+ }
665
+ } else {
666
+ this.addStorageLogEntry(`❌ Key not found or access denied: ${key}`);
667
+ }
668
+ } catch (error) {
669
+ this.addStorageLogEntry(`❌ Error retrieving ${key}: ${error.message}`);
670
+ }
671
+ });
672
+ }
673
+
674
+ if (storageDeleteBtn) {
675
+ storageDeleteBtn.addEventListener('click', async () => {
676
+ const key = document.getElementById('storage-get-key')?.value?.trim();
677
+
678
+ if (!key) {
679
+ this.addStorageLogEntry('❌ Error: Key is required');
680
+ return;
681
+ }
682
+
683
+ if (!confirm(`Are you sure you want to delete "${key}"? This cannot be undone.`)) {
684
+ return;
685
+ }
686
+
687
+ try {
688
+ if (!this.mesh.distributedStorage) {
689
+ this.addStorageLogEntry('❌ Error: Distributed storage not available');
690
+ return;
691
+ }
692
+
693
+ const success = await this.mesh.distributedStorage.delete(key);
694
+ if (success) {
695
+ this.addStorageLogEntry(`🗑️ Deleted: ${key}`);
696
+ this.updateStorageStatus();
697
+ } else {
698
+ this.addStorageLogEntry(`❌ Failed to delete: ${key}`);
699
+ }
700
+ } catch (error) {
701
+ this.addStorageLogEntry(`❌ Error deleting ${key}: ${error.message}`);
702
+ }
703
+ });
704
+ }
705
+
706
+ // Access Control
707
+ const storageGrantAccessBtn = document.getElementById('storage-grant-access-btn');
708
+ const storageRevokeAccessBtn = document.getElementById('storage-revoke-access-btn');
709
+
710
+ if (storageGrantAccessBtn) {
711
+ storageGrantAccessBtn.addEventListener('click', async () => {
712
+ const key = document.getElementById('storage-access-key')?.value?.trim();
713
+ const peerId = document.getElementById('storage-access-peer')?.value?.trim();
714
+ const level = document.getElementById('storage-access-level')?.value;
715
+
716
+ if (!key || !peerId) {
717
+ this.addStorageLogEntry('❌ Error: Key and peer ID are required');
718
+ return;
719
+ }
720
+
721
+ try {
722
+ if (!this.mesh.distributedStorage) {
723
+ this.addStorageLogEntry('❌ Error: Distributed storage not available');
724
+ return;
725
+ }
726
+
727
+ const success = await this.mesh.distributedStorage.grantAccess(key, peerId, level);
728
+ if (success) {
729
+ this.addStorageLogEntry(`✅ Granted ${level} access to ${peerId.substring(0, 8)}... for key: ${key}`);
730
+ } else {
731
+ this.addStorageLogEntry('❌ Failed to grant access');
732
+ }
733
+ } catch (error) {
734
+ this.addStorageLogEntry(`❌ Error granting access: ${error.message}`);
735
+ }
736
+ });
737
+ }
738
+
739
+ if (storageRevokeAccessBtn) {
740
+ storageRevokeAccessBtn.addEventListener('click', async () => {
741
+ const key = document.getElementById('storage-revoke-key')?.value?.trim();
742
+ const peerId = document.getElementById('storage-revoke-peer')?.value?.trim();
743
+
744
+ if (!key || !peerId) {
745
+ this.addStorageLogEntry('❌ Error: Key and peer ID are required');
746
+ return;
747
+ }
748
+
749
+ try {
750
+ if (!this.mesh.distributedStorage) {
751
+ this.addStorageLogEntry('❌ Error: Distributed storage not available');
752
+ return;
753
+ }
754
+
755
+ const success = await this.mesh.distributedStorage.revokeAccess(key, peerId);
756
+ if (success) {
757
+ this.addStorageLogEntry(`✅ Revoked access from ${peerId.substring(0, 8)}... for key: ${key}`);
758
+ } else {
759
+ this.addStorageLogEntry('❌ Failed to revoke access');
760
+ }
761
+ } catch (error) {
762
+ this.addStorageLogEntry(`❌ Error revoking access: ${error.message}`);
763
+ }
764
+ });
765
+ }
766
+
767
+ // Bulk Operations
768
+ const storageListBtn = document.getElementById('storage-list-btn');
769
+ const storageBulkDeleteBtn = document.getElementById('storage-bulk-delete-btn');
770
+
771
+ if (storageListBtn) {
772
+ storageListBtn.addEventListener('click', async () => {
773
+ const prefix = document.getElementById('storage-prefix')?.value?.trim() || '';
774
+
775
+ try {
776
+ if (!this.mesh.distributedStorage) {
777
+ this.addStorageLogEntry('❌ Error: Distributed storage not available');
778
+ return;
779
+ }
780
+
781
+ const keys = await this.mesh.distributedStorage.listKeys(prefix);
782
+ if (keys.length > 0) {
783
+ this.addStorageLogEntry(`📋 Found ${keys.length} keys with prefix "${prefix}":`);
784
+ keys.forEach(key => {
785
+ this.addStorageLogEntry(` • ${key}`);
786
+ });
787
+ } else {
788
+ this.addStorageLogEntry(`❌ No keys found with prefix "${prefix}"`);
789
+ }
790
+ } catch (error) {
791
+ this.addStorageLogEntry(`❌ Error listing keys: ${error.message}`);
792
+ }
793
+ });
794
+ }
795
+
796
+ if (storageBulkDeleteBtn) {
797
+ storageBulkDeleteBtn.addEventListener('click', async () => {
798
+ const prefix = document.getElementById('storage-prefix')?.value?.trim();
799
+
800
+ if (!prefix) {
801
+ this.addStorageLogEntry('❌ Error: Prefix is required for bulk delete');
802
+ return;
803
+ }
804
+
805
+ if (!confirm(`Are you sure you want to delete all keys with prefix "${prefix}"? This cannot be undone.`)) {
806
+ return;
807
+ }
808
+
809
+ try {
810
+ if (!this.mesh.distributedStorage) {
811
+ this.addStorageLogEntry('❌ Error: Distributed storage not available');
812
+ return;
813
+ }
814
+
815
+ const count = await this.mesh.distributedStorage.bulkDelete(prefix);
816
+ this.addStorageLogEntry(`🗑️ Bulk deleted ${count} keys with prefix "${prefix}"`);
817
+ this.updateStorageStatus();
818
+ } catch (error) {
819
+ this.addStorageLogEntry(`❌ Error bulk deleting: ${error.message}`);
820
+ }
821
+ });
822
+ }
823
+
824
+ // Search
825
+ const storageSearchBtn = document.getElementById('storage-search-btn');
826
+
827
+ if (storageSearchBtn) {
828
+ storageSearchBtn.addEventListener('click', async () => {
829
+ const query = document.getElementById('storage-search-query')?.value?.trim();
830
+ const type = document.getElementById('storage-search-type')?.value || 'key';
831
+
832
+ if (!query) {
833
+ this.addStorageLogEntry('❌ Error: Search query is required');
834
+ return;
835
+ }
836
+
837
+ try {
838
+ if (!this.mesh.distributedStorage) {
839
+ this.addStorageLogEntry('❌ Error: Distributed storage not available');
840
+ return;
841
+ }
842
+
843
+ const results = await this.mesh.distributedStorage.search(query, type);
844
+ if (results.length > 0) {
845
+ this.addStorageLogEntry(`🔍 Found ${results.length} results for "${query}" in ${type}:`);
846
+ results.forEach(result => {
847
+ this.addStorageLogEntry(` • ${result.key}: ${JSON.stringify(result.value).substring(0, 100)}...`);
848
+ });
849
+ } else {
850
+ this.addStorageLogEntry(`❌ No results found for "${query}" in ${type}`);
851
+ }
852
+ } catch (error) {
853
+ this.addStorageLogEntry(`❌ Error searching: ${error.message}`);
854
+ }
855
+ });
856
+ }
857
+
858
+ // Backup/Restore
859
+ const storageBackupBtn = document.getElementById('storage-backup-btn');
860
+ const storageRestoreBtn = document.getElementById('storage-restore-btn');
861
+ const storageRestoreFile = document.getElementById('storage-restore-file');
862
+
863
+ if (storageBackupBtn) {
864
+ storageBackupBtn.addEventListener('click', async () => {
865
+ try {
866
+ if (!this.mesh.distributedStorage) {
867
+ this.addStorageLogEntry('❌ Error: Distributed storage not available');
868
+ return;
869
+ }
870
+
871
+ const backup = await this.mesh.distributedStorage.backup();
872
+ const blob = new Blob([JSON.stringify(backup, null, 2)], { type: 'application/json' });
873
+ const url = URL.createObjectURL(blob);
874
+
875
+ const a = document.createElement('a');
876
+ a.href = url;
877
+ a.download = `peerpigeon-storage-backup-${new Date().toISOString().replace(/[:.]/g, '-')}.json`;
878
+ a.click();
879
+
880
+ URL.revokeObjectURL(url);
881
+ this.addStorageLogEntry(`💾 Backup created with ${backup.items.length} items`);
882
+ } catch (error) {
883
+ this.addStorageLogEntry(`❌ Error creating backup: ${error.message}`);
884
+ }
885
+ });
886
+ }
887
+
888
+ if (storageRestoreBtn) {
889
+ storageRestoreBtn.addEventListener('click', () => {
890
+ storageRestoreFile?.click();
891
+ });
892
+ }
893
+
894
+ if (storageRestoreFile) {
895
+ storageRestoreFile.addEventListener('change', async (e) => {
896
+ const file = e.target.files[0];
897
+ if (!file) return;
898
+
899
+ try {
900
+ const text = await file.text();
901
+ const backup = JSON.parse(text);
902
+
903
+ if (!this.mesh.distributedStorage) {
904
+ this.addStorageLogEntry('❌ Error: Distributed storage not available');
905
+ return;
906
+ }
907
+
908
+ const result = await this.mesh.distributedStorage.restore(backup);
909
+ this.addStorageLogEntry(`📥 Restored ${result.restored} items (${result.failed} failed)`);
910
+ this.updateStorageStatus();
911
+ } catch (error) {
912
+ this.addStorageLogEntry(`❌ Error restoring backup: ${error.message}`);
913
+ }
914
+
915
+ // Clear the file input
916
+ e.target.value = '';
917
+ });
918
+ }
919
+ }
920
+
921
+ async handleStorageStore(isUpdate = false) {
922
+ const key = document.getElementById('storage-key')?.value?.trim();
923
+ const value = document.getElementById('storage-value')?.value?.trim();
924
+ const encrypt = document.getElementById('storage-encrypt')?.checked ?? true;
925
+ const isPublic = document.getElementById('storage-public')?.checked ?? false;
926
+ const immutable = document.getElementById('storage-immutable')?.checked ?? false;
927
+ const enableCrdt = document.getElementById('storage-crdt')?.checked ?? false;
928
+ const ttl = parseInt(document.getElementById('storage-ttl')?.value) || 0;
929
+
930
+ if (!key || !value) {
931
+ this.addStorageLogEntry('❌ Error: Both key and value are required');
932
+ return;
933
+ }
934
+
935
+ try {
936
+ if (!this.mesh.distributedStorage) {
937
+ this.addStorageLogEntry('❌ Error: Distributed storage not available');
938
+ return;
939
+ }
940
+
941
+ let parsedValue;
942
+ try {
943
+ parsedValue = JSON.parse(value);
944
+ } catch {
945
+ parsedValue = value; // Use as string if not valid JSON
946
+ }
947
+
948
+ const options = {
949
+ encrypt,
950
+ isPublic,
951
+ isImmutable: immutable,
952
+ enableCRDT: enableCrdt,
953
+ ttl: ttl > 0 ? ttl * 1000 : undefined // Convert to milliseconds
954
+ };
955
+
956
+ let success;
957
+ if (isUpdate) {
958
+ success = await this.mesh.distributedStorage.update(key, parsedValue, options);
959
+ if (success) {
960
+ this.addStorageLogEntry(`🔄 Updated: ${key} = ${JSON.stringify(parsedValue)}`);
961
+ } else {
962
+ this.addStorageLogEntry(`❌ Failed to update: ${key}`);
963
+ }
964
+ } else {
965
+ success = await this.mesh.distributedStorage.store(key, parsedValue, options);
966
+ if (success) {
967
+ this.addStorageLogEntry(`💾 Stored: ${key} = ${JSON.stringify(parsedValue)}`);
968
+ } else {
969
+ this.addStorageLogEntry(`❌ Failed to store: ${key}`);
970
+ }
971
+ }
972
+
973
+ if (success) {
974
+ const optionsStr = [];
975
+ if (encrypt) optionsStr.push('encrypted');
976
+ if (isPublic) optionsStr.push('public');
977
+ if (immutable) optionsStr.push('immutable');
978
+ if (enableCrdt) optionsStr.push('CRDT');
979
+ if (ttl > 0) optionsStr.push(`TTL: ${ttl}s`);
980
+
981
+ if (optionsStr.length > 0) {
982
+ this.addStorageLogEntry(` Options: ${optionsStr.join(', ')}`);
983
+ }
984
+
985
+ this.updateStorageStatus();
986
+ }
987
+ } catch (error) {
988
+ this.addStorageLogEntry(`❌ Error ${isUpdate ? 'updating' : 'storing'} ${key}: ${error.message}`);
989
+ }
990
+ }
991
+
992
+ addStorageLogEntry(message) {
993
+ const logElement = document.getElementById('storage-log');
994
+ if (!logElement) return;
995
+
996
+ const entry = document.createElement('div');
997
+ entry.className = 'log-entry';
998
+ entry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
999
+
1000
+ logElement.appendChild(entry);
1001
+ logElement.scrollTop = logElement.scrollHeight;
1002
+
1003
+ // Keep only last 100 entries
1004
+ while (logElement.children.length > 100) {
1005
+ logElement.removeChild(logElement.firstChild);
1006
+ }
1007
+ }
1008
+
1009
+ updateStorageStatus() {
1010
+ if (!this.mesh.distributedStorage) {
1011
+ document.getElementById('storage-status').textContent = 'Not Available';
1012
+ document.getElementById('storage-item-count').textContent = '0';
1013
+ document.getElementById('storage-total-size').textContent = '0 bytes';
1014
+ return;
1015
+ }
1016
+
1017
+ const isEnabled = this.mesh.distributedStorage.isEnabled();
1018
+ document.getElementById('storage-status').textContent = isEnabled ? 'Enabled' : 'Disabled';
1019
+
1020
+ // Get storage stats if available
1021
+ this.mesh.distributedStorage.getStats().then(stats => {
1022
+ document.getElementById('storage-item-count').textContent = stats.itemCount.toString();
1023
+ document.getElementById('storage-total-size').textContent = this.formatBytes(stats.totalSize);
1024
+ }).catch(() => {
1025
+ document.getElementById('storage-item-count').textContent = '0';
1026
+ document.getElementById('storage-total-size').textContent = '0 bytes';
1027
+ });
1028
+ }
1029
+
1030
+ formatBytes(bytes) {
1031
+ if (bytes === 0) return '0 bytes';
1032
+ const k = 1024;
1033
+ const sizes = ['bytes', 'KB', 'MB', 'GB'];
1034
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
1035
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
1036
+ }
1037
+
523
1038
  setupCryptoControls() {
524
1039
  // Key Management Controls
525
1040
  const generateBtn = document.getElementById('crypto-generate-btn');
@@ -913,6 +1428,7 @@ export class PeerPigeonUI {
913
1428
  'manual-connection',
914
1429
  'settings',
915
1430
  'dht',
1431
+ 'storage',
916
1432
  'crypto',
917
1433
  'media'
918
1434
  ];
@@ -920,8 +1436,25 @@ export class PeerPigeonUI {
920
1436
  sections.forEach(sectionId => {
921
1437
  const toggle = document.getElementById(`${sectionId}-toggle`);
922
1438
  const content = document.getElementById(`${sectionId}-content`);
1439
+ const section = document.querySelector(`.${sectionId}`);
1440
+
1441
+ if (toggle && content && section) {
1442
+ // Force all sections to start collapsed with multiple approaches
1443
+ section.setAttribute('aria-expanded', 'false');
1444
+ toggle.setAttribute('aria-expanded', 'false');
1445
+
1446
+ // Use multiple ways to hide the content
1447
+ content.style.display = 'none';
1448
+ content.style.visibility = 'hidden';
1449
+ content.style.maxHeight = '0';
1450
+ content.style.overflow = 'hidden';
1451
+ content.classList.add('collapsed');
1452
+
1453
+ // Ensure the toggle button shows collapsed state
1454
+ if (toggle.textContent && !toggle.textContent.includes('▶')) {
1455
+ toggle.textContent = toggle.textContent.replace('▼', '▶');
1456
+ }
923
1457
 
924
- if (toggle && content) {
925
1458
  toggle.addEventListener('click', () => {
926
1459
  this.toggleSection(sectionId);
927
1460
  });
@@ -960,10 +1493,20 @@ export class PeerPigeonUI {
960
1493
  }
961
1494
 
962
1495
  if (isExpanded) {
1496
+ // Collapse - hide with multiple approaches
963
1497
  content.style.display = 'none';
1498
+ content.style.visibility = 'hidden';
1499
+ content.style.maxHeight = '0';
1500
+ content.style.overflow = 'hidden';
1501
+ content.classList.add('collapsed');
964
1502
  toggle.textContent = toggle.textContent.replace('▼', '▶');
965
1503
  } else {
1504
+ // Expand - show and reset styles
966
1505
  content.style.display = 'block';
1506
+ content.style.visibility = 'visible';
1507
+ content.style.maxHeight = 'none';
1508
+ content.style.overflow = 'visible';
1509
+ content.classList.remove('collapsed');
967
1510
  toggle.textContent = toggle.textContent.replace('▶', '▼');
968
1511
  }
969
1512
  }
@@ -2039,6 +2582,9 @@ export class PeerPigeonUI {
2039
2582
 
2040
2583
  // Update DHT status
2041
2584
  this.updateDHTStatus();
2585
+
2586
+ // Update storage status
2587
+ this.updateStorageStatus();
2042
2588
  }
2043
2589
 
2044
2590
  updateStatus() {