refactor: improve type safety, Svelte 5 reactivity, and API resilience
This commit is contained in:
@@ -113,15 +113,14 @@ export const get_object = async function get_object({
|
||||
headers: headers,
|
||||
params: params,
|
||||
onDownloadProgress: (progressEvent) => {
|
||||
const percent_completed = Math.round(
|
||||
(progressEvent.loaded * 100) / progressEvent.total
|
||||
);
|
||||
const total = progressEvent.total ?? 0;
|
||||
const percent_completed = total > 0 ? Math.round((progressEvent.loaded * 100) / total) : 0;
|
||||
if (log_lvl > 1) {
|
||||
console.log(
|
||||
'GET Data Progress:',
|
||||
progressEvent.progress,
|
||||
'Total:',
|
||||
progressEvent.total,
|
||||
total,
|
||||
'Loaded:',
|
||||
progressEvent.loaded,
|
||||
'Percent Completed',
|
||||
@@ -142,7 +141,7 @@ export const get_object = async function get_object({
|
||||
task_id: task_id,
|
||||
endpoint: endpoint,
|
||||
filename: filename,
|
||||
size_total: progressEvent.total,
|
||||
size_total: total,
|
||||
size_loaded: progressEvent.loaded,
|
||||
percent_completed: percent_completed
|
||||
},
|
||||
@@ -328,14 +327,13 @@ export const get_object = async function get_object({
|
||||
params: params,
|
||||
responseType: 'blob',
|
||||
onDownloadProgress: (progressEvent) => {
|
||||
const percent_completed = Math.round(
|
||||
(progressEvent.loaded * 100) / progressEvent.total
|
||||
);
|
||||
const total = progressEvent.total ?? 0;
|
||||
const percent_completed = total > 0 ? Math.round((progressEvent.loaded * 100) / total) : 0;
|
||||
console.log(
|
||||
'GET Blob Progress:',
|
||||
progressEvent.progress,
|
||||
'Total:',
|
||||
progressEvent.total,
|
||||
total,
|
||||
'Loaded:',
|
||||
progressEvent.loaded,
|
||||
'Percent Completed',
|
||||
@@ -354,7 +352,7 @@ export const get_object = async function get_object({
|
||||
task_id: task_id,
|
||||
endpoint: endpoint,
|
||||
filename: filename,
|
||||
size_total: progressEvent.total,
|
||||
size_total: total,
|
||||
size_loaded: progressEvent.loaded,
|
||||
percent_completed: percent_completed
|
||||
},
|
||||
@@ -414,7 +412,7 @@ export const get_object = async function get_object({
|
||||
const url = window.URL.createObjectURL(new Blob([response.data]));
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.setAttribute('download', filename);
|
||||
link.setAttribute('download', filename || 'download');
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user