@@ -253,52 +253,8 @@ impl PutWindow {
253253// Update total chunks
254254* self . total_chunks . write ( ) . unwrap ( ) = total_chunks;
255255
256- // Check if current phase is complete
257- if confirmed_count == total_chunks && total_chunks >0 {
258- let current_phase =* self . current_phase . read ( ) . unwrap ( ) ;
259- let is_public =* self . public . read ( ) . unwrap ( ) ;
260-
261- if current_phase ==1 {
262- // Phase 1 (file data) is complete
263- * self . phase1_complete . write ( ) . unwrap ( ) =true ;
264-
265- // Store Phase 1 progress
266- * self . phase1_reservation_progress . write ( ) . unwrap ( ) =* self . reservation_progress . read ( ) . unwrap ( ) ;
267- * self . phase1_upload_progress . write ( ) . unwrap ( ) =* self . upload_progress . read ( ) . unwrap ( ) ;
268- * self . phase1_confirmation_progress . write ( ) . unwrap ( ) =* self . confirmation_progress . read ( ) . unwrap ( ) ;
269- * self . phase1_total_chunks . write ( ) . unwrap ( ) =* self . total_chunks . read ( ) . unwrap ( ) ;
270-
271- if is_public{
272- // For public uploads, move to Phase 2 (public index upload)
273- * self . current_phase . write ( ) . unwrap ( ) =2 ;
274-
275- // Reset current progress for Phase 2
276- * self . reservation_progress . write ( ) . unwrap ( ) =0.0 ;
277- * self . upload_progress . write ( ) . unwrap ( ) =0.0 ;
278- * self . confirmation_progress . write ( ) . unwrap ( ) =0.0 ;
279- * self . total_chunks . write ( ) . unwrap ( ) =0 ;
280-
281- // Don't mark as complete yet - wait for Phase 2
282- log:: info!( "Phase 1 complete, starting Phase 2 (public index upload)" ) ;
283- } else {
284- // For private uploads, we're done after Phase 1
285- self . complete_upload ( ) ;
286- }
287- } else if current_phase ==2 {
288- // Phase 2 (public index) is complete
289- * self . phase2_complete . write ( ) . unwrap ( ) =true ;
290-
291- // Store Phase 2 progress
292- * self . phase2_reservation_progress . write ( ) . unwrap ( ) =* self . reservation_progress . read ( ) . unwrap ( ) ;
293- * self . phase2_upload_progress . write ( ) . unwrap ( ) =* self . upload_progress . read ( ) . unwrap ( ) ;
294- * self . phase2_confirmation_progress . write ( ) . unwrap ( ) =* self . confirmation_progress . read ( ) . unwrap ( ) ;
295- * self . phase2_total_chunks . write ( ) . unwrap ( ) =* self . total_chunks . read ( ) . unwrap ( ) ;
296-
297- // Both phases complete for public upload
298- self . complete_upload ( ) ;
299- log:: info!( "Phase 2 complete, public upload finished" ) ;
300- }
301- }
256+ // Note: Phase detection is now handled in the real-time progress receiver
257+ // This polling-based checker is kept for backward compatibility but phase logic moved
302258}
303259}
304260}
@@ -984,6 +940,21 @@ impl PutWindow {
984940let initial_written_count =self . initial_written_count . clone ( ) ;
985941let initial_confirmed_count =self . initial_confirmed_count . clone ( ) ;
986942
943+ // Store phase tracking references
944+ let current_phase =self . current_phase . clone ( ) ;
945+ let phase1_complete =self . phase1_complete . clone ( ) ;
946+ let phase2_complete =self . phase2_complete . clone ( ) ;
947+ let phase1_reservation_progress =self . phase1_reservation_progress . clone ( ) ;
948+ let phase1_upload_progress =self . phase1_upload_progress . clone ( ) ;
949+ let phase1_confirmation_progress =self . phase1_confirmation_progress . clone ( ) ;
950+ let phase1_total_chunks =self . phase1_total_chunks . clone ( ) ;
951+ let phase2_reservation_progress =self . phase2_reservation_progress . clone ( ) ;
952+ let phase2_upload_progress =self . phase2_upload_progress . clone ( ) ;
953+ let phase2_confirmation_progress =self . phase2_confirmation_progress . clone ( ) ;
954+ let phase2_total_chunks =self . phase2_total_chunks . clone ( ) ;
955+ let public_address =self . public_address . clone ( ) ;
956+ let key_name_clone = key_name. clone ( ) ;
957+
987958spawn_local ( async move {
988959 log:: info!( "Starting file path upload: {} -> {}" , file_path, key_name) ;
989960match ctx
@@ -1079,12 +1050,81 @@ impl PutWindow {
10791050}
10801051}
10811052 mutant_protocol:: PutEvent :: Complete =>{
1082- log:: info!(
1083- "Put operation completed successfully"
1084- ) ;
1085- * upload_complete_clone. write ( ) . unwrap ( ) =true ;
1086- * is_uploading_clone. write ( ) . unwrap ( ) =false ;
1087- break ;
1053+ log:: info!( "Put operation phase completed successfully" ) ;
1054+
1055+ // Check which phase just completed
1056+ let current_phase_val =* current_phase. read ( ) . unwrap ( ) ;
1057+
1058+ if current_phase_val ==1 {
1059+ // Phase 1 (file data) is complete
1060+ * phase1_complete. write ( ) . unwrap ( ) =true ;
1061+
1062+ // Store Phase 1 progress
1063+ * phase1_reservation_progress. write ( ) . unwrap ( ) =* reservation_progress. read ( ) . unwrap ( ) ;
1064+ * phase1_upload_progress. write ( ) . unwrap ( ) =* upload_progress. read ( ) . unwrap ( ) ;
1065+ * phase1_confirmation_progress. write ( ) . unwrap ( ) =* confirmation_progress. read ( ) . unwrap ( ) ;
1066+ * phase1_total_chunks. write ( ) . unwrap ( ) =* total_chunks. read ( ) . unwrap ( ) ;
1067+
1068+ if public{
1069+ // For public uploads, move to Phase 2 (public index upload)
1070+ * current_phase. write ( ) . unwrap ( ) =2 ;
1071+
1072+ // Reset current progress for Phase 2
1073+ * reservation_progress. write ( ) . unwrap ( ) =0.0 ;
1074+ * upload_progress. write ( ) . unwrap ( ) =0.0 ;
1075+ * confirmation_progress. write ( ) . unwrap ( ) =0.0 ;
1076+ * total_chunks. write ( ) . unwrap ( ) =0 ;
1077+
1078+ // Don't mark as complete yet - wait for Phase 2
1079+ log:: info!( "Phase 1 complete, waiting for Phase 2 (public index upload)" ) ;
1080+ // Continue listening for Phase 2 events
1081+ } else {
1082+ // For private uploads, we're done after Phase 1
1083+ * upload_complete_clone. write ( ) . unwrap ( ) =true ;
1084+ * is_uploading_clone. write ( ) . unwrap ( ) =false ;
1085+
1086+ // Refresh the keys list
1087+ spawn_local ( async move {
1088+ let ctx = context:: context ( ) ;
1089+ let _ = ctx. list_keys ( ) . await ;
1090+ } ) ;
1091+
1092+ break ;
1093+ }
1094+ } else if current_phase_val ==2 {
1095+ // Phase 2 (public index) is complete
1096+ * phase2_complete. write ( ) . unwrap ( ) =true ;
1097+
1098+ // Store Phase 2 progress
1099+ * phase2_reservation_progress. write ( ) . unwrap ( ) =* reservation_progress. read ( ) . unwrap ( ) ;
1100+ * phase2_upload_progress. write ( ) . unwrap ( ) =* upload_progress. read ( ) . unwrap ( ) ;
1101+ * phase2_confirmation_progress. write ( ) . unwrap ( ) =* confirmation_progress. read ( ) . unwrap ( ) ;
1102+ * phase2_total_chunks. write ( ) . unwrap ( ) =* total_chunks. read ( ) . unwrap ( ) ;
1103+
1104+ // Both phases complete for public upload
1105+ * upload_complete_clone. write ( ) . unwrap ( ) =true ;
1106+ * is_uploading_clone. write ( ) . unwrap ( ) =false ;
1107+
1108+ // Refresh the keys list and get public address
1109+ spawn_local ( async move {
1110+ let ctx = context:: context ( ) ;
1111+ let _ = ctx. list_keys ( ) . await ;
1112+
1113+ // Fetch the key details to get the public address
1114+ let keys = ctx. list_keys ( ) . await ;
1115+ for keyin keys{
1116+ if key. key == key_name_clone && key. is_public {
1117+ if let Some ( addr) = key. public_address {
1118+ * public_address. write ( ) . unwrap ( ) =Some ( addr) ;
1119+ break ;
1120+ }
1121+ }
1122+ }
1123+ } ) ;
1124+
1125+ log:: info!( "Phase 2 complete, public upload finished" ) ;
1126+ break ;
1127+ }
10881128}
10891129}
10901130}