@@ -834,6 +834,43 @@ function initUploader(path, _parent, el, labels) {
834
834
</div>
835
835
` ;
836
836
document . body . appendChild ( qqTemplate ) ;
837
+
838
+ function pollForTaskProgress ( taskId , listItem , fileName ) {
839
+ let taskStatus = 'pending' ;
840
+ const pollingInterval = 10000 ; // 10 seconds
841
+
842
+ const doPoll = function ( ) {
843
+ if ( taskStatus === 'pending' ) {
844
+ $ . get ( '/desktop/api2/taskserver/check_upload_status/' + taskId , data => {
845
+ if ( data . isFinalized || data . isFailure || data . is_revoked ) {
846
+ taskStatus = data . isFinalized ? 'finalized' : 'failed' ;
847
+
848
+ if ( data . isFinalized ) {
849
+ huePubSub . publish ( 'hue.global.info' , {
850
+ message : fileName + ' uploaded successfully.'
851
+ } ) ;
852
+ if ( ! num_of_pending_uploads ) {
853
+ _parent . navigateTo ( path ) ;
854
+ huePubSub . publish ( 'assist.' + getFs ( getScheme ( path ) ) + '.refresh' ) ;
855
+ }
856
+ } else if ( data . isFailure ) {
857
+ huePubSub . publish ( 'hue.global.error' , {
858
+ message : fileName + ' upload failed. Please check the logs for task id: ' + taskId
859
+ } ) ;
860
+ }
861
+ } else if ( data . isRunning ) {
862
+ setTimeout ( doPoll , pollingInterval ) ;
863
+ }
864
+ } ) . fail ( xhr => {
865
+ if ( xhr . status === 404 ) {
866
+ setTimeout ( doPoll , pollingInterval ) ; // Retry after interval
867
+ }
868
+ } ) ;
869
+ }
870
+ } ;
871
+ doPoll ( ) ;
872
+ }
873
+
837
874
uploader = new qq . FileUploader ( {
838
875
element : el [ 0 ] ,
839
876
request : {
@@ -866,13 +903,35 @@ function initUploader(path, _parent, el, labels) {
866
903
callbacks : {
867
904
onComplete : function ( id , fileName , response ) {
868
905
num_of_pending_uploads -- ;
906
+ const listItem = $ ( '.qq-upload-files' )
907
+ . find ( 'li' )
908
+ . filter ( function ( ) {
909
+ return $ ( this ) . find ( '.qq-upload-file-selector' ) . text ( ) === fileName ;
910
+ } ) ;
911
+
869
912
if ( response . status != 0 ) {
870
913
huePubSub . publish ( 'hue.global.error' , { message : response . data } ) ;
871
- } else if ( ! num_of_pending_uploads ) {
872
- _parent . navigateTo ( path ) ;
873
- huePubSub . publish ( 'assist.' + getFs ( getScheme ( path ) ) + '.refresh' ) ;
914
+ } else {
915
+ const taskId = response . task_id ;
916
+
917
+ if ( taskId ) {
918
+ // polling for task progress
919
+ setTimeout ( ( ) => {
920
+ pollForTaskProgress ( taskId , listItem , fileName , path ) ;
921
+ } , 2000 ) ; // Delay to ensure task is started
922
+ } else {
923
+ // No task_id, consider upload complete
924
+ huePubSub . publish ( 'hue.global.info' , {
925
+ message : fileName + ' uploaded successfully.'
926
+ } ) ;
927
+ if ( ! num_of_pending_uploads ) {
928
+ _parent . navigateTo ( path ) ;
929
+ huePubSub . publish ( 'assist.' + getFs ( getScheme ( path ) ) + '.refresh' ) ;
930
+ }
931
+ }
874
932
}
875
933
} ,
934
+
876
935
onSubmit : function ( id , fileName ) {
877
936
const newPath =
878
937
'/filebrowser/upload/chunks/file?dest=' + encodeURIComponent ( path . normalize ( 'NFC' ) ) ;
0 commit comments