From 33a107d3472ad5f97f73cc6c5b2bb38a4b5295b7 Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Wed, 28 Apr 2021 17:57:49 +0200 Subject: [PATCH] Large file transfers --- Cargo.toml | 3 +- src/constants.rs | 3 +- src/discovery.rs | 8 +- src/frontend/commons/script.js | 2 +- src/frontend/index.css | 60 ++- src/frontend/index.html | 18 +- src/frontend/index.js | 796 ++++++++++++++++++++------------ src/frontend/login.html | 2 +- src/identity.rs | 6 +- src/main.rs | 118 ++++- src/session_manager/mod.rs | 521 +++++++++++++++------ src/session_manager/protocol.rs | 9 + src/session_manager/session.rs | 22 +- src/ui_interface.rs | 92 +++- src/utils.rs | 6 +- 15 files changed, 1165 insertions(+), 501 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ca611bc..f8b1a88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,8 @@ futures = "0.3" tungstenite = "0.13.0" #websocket serde = "1.0.124" #serialization html-escape = "0.2.7" -dirs = "3.0" +sanitize-filename = "0.3" +platform-dirs = "0.3.0" uuid = {version = "0.8", features = ["v4"]} webbrowser = "0.5.5" libmdns = "0.6" #mDNS advertiser diff --git a/src/constants.rs b/src/constants.rs index 7bbecaa..d79ffe3 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -3,4 +3,5 @@ pub const UI_PORT: u16 = 9510; pub const APPLICATION_FOLDER: &str = "AIRA"; pub const DB_NAME: &str = "AIRA.db"; pub const HTTP_COOKIE_NAME: &str = "aira_auth"; -pub const MSG_LOADING_COUNT: usize = 20; \ No newline at end of file +pub const MSG_LOADING_COUNT: usize = 20; +pub const FILE_CHUNK_SIZE: usize = 1023996; \ No newline at end of file diff --git a/src/discovery.rs b/src/discovery.rs index eed0d30..3625b6a 100644 --- a/src/discovery.rs +++ b/src/discovery.rs @@ -1,17 +1,17 @@ -use std::{net::IpAddr}; +use std::{net::IpAddr, io}; use libmdns::{Responder, Service}; use multicast_dns::discovery::{DiscoveryManager, DiscoveryListeners, ResolveListeners}; use crate::{constants, print_error}; const SERVICE_TYPE: &str = "_aira._tcp"; -pub fn advertise_me() -> Service { - Responder::new().unwrap().register( +pub fn advertise_me() -> io::Result { + Ok(Responder::new()?.register( SERVICE_TYPE.to_string(), "AIRA Node".to_string(), constants::PORT, &[] - ) + )) } pub fn discover_peers(on_service_discovered: F) { diff --git a/src/frontend/commons/script.js b/src/frontend/commons/script.js index 9dc7cf9..5c3bce6 100644 --- a/src/frontend/commons/script.js +++ b/src/frontend/commons/script.js @@ -1,4 +1,4 @@ -function generate_avatar(name){ +function generateAvatar(name){ let span = document.createElement("span"); if (typeof name == "undefined"){ span.appendChild(document.createTextNode("?")); diff --git a/src/frontend/index.css b/src/frontend/index.css index ae9927b..0170aad 100644 --- a/src/frontend/index.css +++ b/src/frontend/index.css @@ -84,7 +84,7 @@ input[type="file"] { font-size: 4em; margin: auto; } -.popup>div>div, .popup>div>button { +.popup section { font-weight: bold; display: block; margin-bottom: 1em; @@ -104,16 +104,23 @@ input[type="file"] { .popup button:hover { background-color: var(--accent); } +.popup span { + font-weight: bold; +} .popup>div>div p { font-weight: normal; font-size: 0.9em; } -.popup h2::before { +.popup h2.warning::before { content: url("/static/imgs/icons/warning/FF3C00"); width: 9%; display: inline-block; vertical-align: middle; } +.button_row { + display: flex; + gap: 15px; +} .section_title { margin-left: 8px; font-weight: bold; @@ -272,6 +279,55 @@ input[type="file"] { padding: 1em; font-size: 1.1em; } +#file_transfer { + border-top: 2px solid var(--accent); + display: none; + position: relative; +} +#file_transfer.active { + display: block; +} +#file_transfer span { + font-weight: bold; +} +#file_control { + display: flex; + align-items: center; +} +#file_cancel { + padding: 0; +} +#file_cancel::after { + background-color: unset; + width: 1.2em; + content: url("/static/imgs/icons/cancel/FF3C00"); +} +#file_progress { + display: none; + gap: 10px; + align-items: center; + margin-bottom: 15px; +} +#file_transfer.active>#file_progress { + display: flex; +} +#file_status { + margin-top: 0; +} +#file_percent, #file_speed { + font-weight: bold; + margin: 0; + border-left: 2px solid var(--accent); + padding-left: 10px; +} +#file_progress_bar { + flex-grow: 1; + height: 1.5em; +} +#file_progress_bar div { + height: 100%; + background-color: var(--accent); +} #message_box { border-top: 2px solid var(--accent); margin-bottom: 0; diff --git a/src/frontend/index.html b/src/frontend/index.html index d77dc1d..3e42a5d 100644 --- a/src/frontend/index.html +++ b/src/frontend/index.html @@ -37,6 +37,20 @@
+
+
+ +

+
+

+
+

+

+
+
+
+
+