Fix single upload at a time

This commit is contained in:
ABelliqueux 2023-01-11 15:22:12 +01:00
parent 6872e3f7ed
commit fb186c1c73
4 changed files with 44 additions and 43 deletions

13
app.py
View File

@ -237,8 +237,8 @@ def HTTP_upload(file_dict, host_local, port):
# ~ response = requests.post(url, files=files, headers=http_headers, verify=CAfile) # ~ response = requests.post(url, files=files, headers=http_headers, verify=CAfile)
response = requests.post(url, data=data, headers=http_headers, verify=CAfile) response = requests.post(url, data=data, headers=http_headers, verify=CAfile)
# ~ response = requests.post(url, data=data, headers=http_headers, verify=CAfile) # ~ response = requests.post(url, data=data, headers=http_headers, verify=CAfile)
if debug: # ~ if debug:
print(response.text) # ~ print(response.text)
transferred_mb = len(data) / 1024 / 1024 transferred_mb = len(data) / 1024 / 1024
current_upload["transferred_size"] += round(transferred_mb) current_upload["transferred_size"] += round(transferred_mb)
current_upload["transferred_percent"] += round(100 / current_upload["total_size"] * transferred_mb) current_upload["transferred_percent"] += round(100 / current_upload["total_size"] * transferred_mb)
@ -534,9 +534,9 @@ def send_pilpil_command(host, arg0, arg1, arg2):
# Send request and get data response # Send request and get data response
data = send_HTTP_request(host, port_, time_out=3, request_=HTTP_request) data = send_HTTP_request(host, port_, time_out=3, request_=HTTP_request)
if debug: # ~ if debug:
if data: # ~ if data:
print(str(host) + " - data length:" + str(len(data)) + " : " + str(data)) # ~ print(str(host) + " - data length:" + str(len(data)) + " : " + str(data))
if not data: if not data:
print("No data was received.") print("No data was received.")
return 0 return 0
@ -672,4 +672,5 @@ def action(host, arg0, arg1, arg2):
if __name__ == '__main__': if __name__ == '__main__':
# ~ app.run() # ~ app.run()
serve(app, host='127.0.0.1', port=8080) HTTP_url_scheme = "http"
serve(app, host='127.0.0.1', port=5000, url_scheme=HTTP_url_scheme)

5
serve_app.sh Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env bash
cd "$(dirname "$0")"
waitress-serve --listen=127.0.0.1:5000 app:app

View File

@ -71,11 +71,9 @@ async function update_sort_VLC_playlist(host) {
currentUser.freeze_timeline_update = 0; currentUser.freeze_timeline_update = 0;
} }
function get_child_by_id(id, parent_element, depth=0){ function get_child_by_id(id, parent_element, depth=0){
// TODO : fix this ofc
Array.from(parent_element.children).forEach(function(child){ Array.from(parent_element.children).forEach(function(child){
if (depth){ if (depth){
if (child.children[0].id == id){ if (child.children[0].id == id){
//~ console.log(child.children[0]);
result = child.children[0]; result = child.children[0];
} }
} else if (child.id == id) { } else if (child.id == id) {
@ -401,23 +399,21 @@ function update_rssi_indicator(infos_array_element){
} }
function update_local_filelist(infos_array) { //~ function update_local_filelist(infos_array) {
// TODO : Is this useful ? //~ let html_table = "<table>" +
// TODO : Get real media length //~ "<tr>" +
let html_table = "<table>" + //~ "<th>" + t9n[LOCALE].filename + "</th>" +
"<tr>" + //~ "<th>" + t9n[LOCALE].duration + "</th>" +
"<th>" + t9n[LOCALE].filename + "</th>" + //~ "</tr>";
"<th>" + t9n[LOCALE].duration + "</th>" + //~ infos_array.forEach(function(element){
"</tr>"; //~ html_table += "<tr>" +
infos_array.forEach(function(element){ //~ "<td>" + element + "</td>" +
html_table += "<tr>" + //~ "<td>" + "00:00" + "</td>" +
"<td>" + element + "</td>" + //~ "</tr>" ;
"<td>" + "00:00" + "</td>" + //~ });
"</tr>" ; //~ html_table += "</table>";
}); //~ return html_table;
html_table += "</table>"; //~ }
return html_table;
}
function update_host_list(infos_array){ function update_host_list(infos_array){
@ -487,24 +483,24 @@ function display_upload_status(command) {
} }
function destroy_upload_status() { function destroy_upload_status(host) {
let container_element = document.getElementById(currentUser.last_ul_host); let container_element = document.getElementById(host);
let ul_cont_exists = document.getElementById("ul_dialog_cont_" + currentUser.last_ul_host); let ul_cont_exists = document.getElementById("ul_dialog_cont_" + host);
if ( ul_cont_exists != undefined) { if ( ul_cont_exists != undefined) {
container_element.removeChild(ul_cont_exists); container_element.removeChild(ul_cont_exists);
clearTimeout(currentUser["ul_timeout_" + currentUser.last_ul_host]); clearTimeout(currentUser["ul_timeout_" + host]);
} }
} }
async function update_upload_status(current_upload) { async function update_upload_status(current_upload) {
console.log("Updating upload status..."); //~ console.log("Updating upload status...");
//~ console.log(current_upload); //~ console.log(current_upload);
if (current_upload.status == -1){ if (current_upload.status == -1){
console.log("Destroying dialog..." + current_upload.host); console.log("Destroying dialog..." + currentUser.last_ul_host);
destroy_upload_status(); destroy_upload_status(currentUser.last_ul_host);
} else if (current_upload.status) { } else if (current_upload.status) {
console.log("Filling dialog..."); //~ console.log("Filling dialog...");
document.getElementById("ul_dialog_cont_" + current_upload.host).style.display = "block"; document.getElementById("ul_dialog_cont_" + current_upload.host).style.display = "block";
// Fill table // Fill table
document.getElementById("ul_status_progress_cnt_" + current_upload.host).innerHTML = current_upload.progress + " / " + current_upload.total_count + t9n[LOCALE].upload_sent_count_msg; document.getElementById("ul_status_progress_cnt_" + current_upload.host).innerHTML = current_upload.progress + " / " + current_upload.total_count + t9n[LOCALE].upload_sent_count_msg;
@ -518,7 +514,7 @@ async function update_upload_status(current_upload) {
} }
currentUser["ul_timeout_" + current_upload.host] = setTimeout(send_ajax_cmd, 3000, `/sync/${current_upload.host}/status`); currentUser["ul_timeout_" + current_upload.host] = setTimeout(send_ajax_cmd, 3000, `/sync/${current_upload.host}/status`);
} else { } else {
console.log("requesting status data"); //~ console.log("requesting status data");
currentUser.last_ul_host = current_upload.host; currentUser.last_ul_host = current_upload.host;
send_ajax_cmd(`/sync/${current_upload.host}/status`); send_ajax_cmd(`/sync/${current_upload.host}/status`);
await sleep(500); await sleep(500);
@ -545,7 +541,7 @@ function parse_result(command, infos_array) {
} else if (command == "/browse_local") { } else if (command == "/browse_local") {
// Display local media files in a table // Display local media files in a table
document.getElementById("filelist").innerHTML = update_local_filelist(infos_array); //~ document.getElementById("filelist").innerHTML = update_local_filelist(infos_array);
} else if (command == "/all/rssi") { } else if (command == "/all/rssi") {
// RSSI strength indicator // RSSI strength indicator
@ -558,15 +554,15 @@ function parse_result(command, infos_array) {
} else if (command.indexOf("/sync/") > -1) { } else if (command.indexOf("/sync/") > -1) {
if (command.indexOf("/status") > -1 ) { if (command.indexOf("/status") > -1 ) {
console.log("updating infos..."); //~ console.log("updating infos...");
console.log(infos_array); //~ console.log(infos_array);
update_upload_status(infos_array); update_upload_status(infos_array);
} else if (command.indexOf("/stop") > -1 ) { } else if (command.indexOf("/stop") > -1 ) {
console.log("stopping upload..."); //~ console.log("stopping upload...");
console.log(infos_array); //~ console.log(infos_array);
destroy_upload_status(); //~ destroy_upload_status();
} else { } else {
console.log("displaying status"); //~ console.log("displaying status");
//~ console.log(infos_array); //~ console.log(infos_array);
//~ if (infos_array.total_count) { //~ if (infos_array.total_count) {
//~ display_upload_status(infos_array) //~ display_upload_status(infos_array)
@ -650,7 +646,6 @@ addEventListener("DOMContentLoaded", function() {
clickedButton.value = clickedButton.value.replace('/0/','/1/'); clickedButton.value = clickedButton.value.replace('/0/','/1/');
} }
} }
// AJAX request // AJAX request
let request = new XMLHttpRequest(); let request = new XMLHttpRequest();
if ( command == "/scan") { if ( command == "/scan") {