Now with upload and download percent! Also better editing for session POC.

This commit is contained in:
Scott Idem
2024-06-21 12:25:36 -04:00
parent fd114bce22
commit 2552e1a839
11 changed files with 433 additions and 64 deletions

View File

@@ -36,7 +36,7 @@ export let get_object = async function get_object(
timeout?: number,
return_meta?: boolean,
return_blob?: boolean,
filename?: string,
filename?: null|string,
auto_download?: boolean,
as_list?: boolean,
task_id?: string,
@@ -119,9 +119,27 @@ export let get_object = async function get_object(
let percent_completed = Math.round(
(progressEvent.loaded * 100) / progressEvent.total
);
// console.log('GET Data Timestamp:', progressEvent.timeStamp, 'Total:', progressEvent.total, 'Loaded:', progressEvent.loaded, 'Percent Completed', percent_completed);
console.log('GET Data Progress:', progressEvent.progress, 'Total:', progressEvent.total, 'Loaded:', progressEvent.loaded, 'Percent Completed', percent_completed);
temp_get_object_percent_completed = percent_completed;
// WARNING: This needs to be tied to an object type and ID. This is a temporary solution.
try {
window.postMessage({
type: 'api_download_data',
status: 'downloading',
task_id: task_id,
endpoint: endpoint,
filename: filename,
size_total: progressEvent.total,
size_loaded: progressEvent.loaded,
percent_completed: percent_completed,
},
'*'
);
} catch (error) {
console.log('Error posting message to window:', error);
}
}
}
)
@@ -132,6 +150,25 @@ export let get_object = async function get_object(
if (log_lvl > 1) {
console.log('GET Response:', response);
}
// Post file download message
try {
window.postMessage({
type: 'api_download_data',
status: 'complete',
task_id: task_id,
endpoint: endpoint,
filename: filename,
size_total: 0,
size_loaded: 0,
percent_completed: 100,
},
'*'
);
} catch (error) {
console.log('Error posting message to window:', error);
}
if (!Array.isArray(response.data['data']) && as_list) {
if (log_lvl) {
console.log('Data result is a dictionary/object, not an array/list. Forcing return as an array/list');
@@ -252,11 +289,13 @@ export let get_object = async function get_object(
try {
window.postMessage({
type: 'api_download_blob',
status: 'downloading',
task_id: task_id,
endpoint: endpoint,
filename: filename,
size_total: progressEvent.total,
size_loaded: progressEvent.loaded,
percent_completed: percent_completed
percent_completed: percent_completed,
},
'*'
);
@@ -287,7 +326,14 @@ export let get_object = async function get_object(
// WARNING: This needs to be tied to an object type and ID. This is a temporary solution.
try {
window.postMessage({
type: 'api_download_blob', endpoint: endpoint, filename: filename, size_total: 0, size_loaded: 0, percent_completed: 100
type: 'api_download_blob',
status: 'complete',
task_id: task_id,
endpoint: endpoint,
filename: filename,
size_total: 0,
size_loaded: 0,
percent_completed: 100,
},
'*'
);