Skip to content

Commit b3c641e

Browse files
Importer not auto refreshing for file uploads with task server
1 parent 382177d commit b3c641e

File tree

1 file changed

+62
-3
lines changed

1 file changed

+62
-3
lines changed

desktop/core/src/desktop/js/jquery/plugins/jquery.filechooser.js

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,43 @@ function initUploader(path, _parent, el, labels) {
834834
</div>
835835
`;
836836
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+
837874
uploader = new qq.FileUploader({
838875
element: el[0],
839876
request: {
@@ -866,13 +903,35 @@ function initUploader(path, _parent, el, labels) {
866903
callbacks: {
867904
onComplete: function (id, fileName, response) {
868905
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+
869912
if (response.status != 0) {
870913
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+
}
874932
}
875933
},
934+
876935
onSubmit: function (id, fileName) {
877936
const newPath =
878937
'/filebrowser/upload/chunks/file?dest=' + encodeURIComponent(path.normalize('NFC'));

0 commit comments

Comments
 (0)