aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock117
-rw-r--r--Cargo.toml5
-rw-r--r--server/Cargo.toml1
-rw-r--r--server/src/routes/mod.rs4
-rw-r--r--server/src/routes/stream.rs2
-rw-r--r--server/src/routes/streamsync.rs11
-rw-r--r--server/src/routes/ui/account/mod.rs8
-rw-r--r--server/src/routes/ui/account/session/guard.rs2
8 files changed, 111 insertions, 39 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 806d9c8..5712524 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -539,9 +539,9 @@ dependencies = [
[[package]]
name = "cookie"
-version = "0.17.0"
+version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7efb37c3e1ccb1ff97164ad95ac1606e8ccd35b3fa0a7d99a304c7f4a428cc24"
+checksum = "3cd91cf61412820176e137621345ee43b3f4423e589e7ae4e50d601d93e35ef8"
dependencies = [
"aes-gcm",
"base64",
@@ -647,6 +647,12 @@ dependencies = [
]
[[package]]
+name = "data-encoding"
+version = "2.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5"
+
+[[package]]
name = "deranged"
version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1018,7 +1024,7 @@ dependencies = [
"futures-sink",
"futures-util",
"http",
- "indexmap 2.1.0",
+ "indexmap",
"slab",
"tokio",
"tokio-util",
@@ -1036,12 +1042,6 @@ dependencies = [
[[package]]
name = "hashbrown"
-version = "0.12.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
-
-[[package]]
-name = "hashbrown"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
@@ -1213,23 +1213,13 @@ checksum = "90d944e334f00f4449c9640b440a171f816be0152305c12ef90424fc35fd035c"
[[package]]
name = "indexmap"
-version = "1.9.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
-dependencies = [
- "autocfg",
- "hashbrown 0.12.3",
- "serde",
-]
-
-[[package]]
-name = "indexmap"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
dependencies = [
"equivalent",
- "hashbrown 0.14.3",
+ "hashbrown",
+ "serde",
]
[[package]]
@@ -1439,6 +1429,7 @@ dependencies = [
"markup",
"rand",
"rocket",
+ "rocket_ws",
"serde",
"serde_json",
"tokio",
@@ -2354,8 +2345,9 @@ dependencies = [
[[package]]
name = "rocket"
-version = "0.5.0-rc.3"
-source = "git+https://github.com/SergioBenitez/Rocket?rev=2cf38a5aa37fe046e46b03740835787f0396307b#2cf38a5aa37fe046e46b03740835787f0396307b"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9e7bb57ccb26670d73b6a47396c83139447b9e7878cab627fdfe9ea8da489150"
dependencies = [
"async-stream",
"async-trait",
@@ -2365,7 +2357,7 @@ dependencies = [
"either",
"figment",
"futures",
- "indexmap 1.9.3",
+ "indexmap",
"log",
"memchr",
"multer",
@@ -2391,30 +2383,33 @@ dependencies = [
[[package]]
name = "rocket_codegen"
-version = "0.5.0-rc.3"
-source = "git+https://github.com/SergioBenitez/Rocket?rev=2cf38a5aa37fe046e46b03740835787f0396307b#2cf38a5aa37fe046e46b03740835787f0396307b"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a2238066abf75f21be6cd7dc1a09d5414a671f4246e384e49fe3f8a4936bd04c"
dependencies = [
"devise",
"glob",
- "indexmap 1.9.3",
+ "indexmap",
"proc-macro2",
"quote",
"rocket_http",
"syn 2.0.48",
"unicode-xid",
+ "version_check",
]
[[package]]
name = "rocket_http"
-version = "0.5.0-rc.3"
-source = "git+https://github.com/SergioBenitez/Rocket?rev=2cf38a5aa37fe046e46b03740835787f0396307b#2cf38a5aa37fe046e46b03740835787f0396307b"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "37a1663694d059fe5f943ea5481363e48050acedd241d46deb2e27f71110389e"
dependencies = [
"cookie",
"either",
"futures",
"http",
"hyper",
- "indexmap 1.9.3",
+ "indexmap",
"log",
"memchr",
"pear",
@@ -2431,6 +2426,16 @@ dependencies = [
]
[[package]]
+name = "rocket_ws"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b6677b3fe72e2d73dd632c412546ed8153e8685c830ee8d20e4488575cb905d9"
+dependencies = [
+ "rocket",
+ "tokio-tungstenite",
+]
+
+[[package]]
name = "rust_hawktracer"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2603,7 +2608,7 @@ version = "0.9.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cc7a1570e38322cfe4154732e5110f887ea57e22b76f4bfd32b5bdd3368666c"
dependencies = [
- "indexmap 2.1.0",
+ "indexmap",
"itoa",
"ryu",
"serde",
@@ -2611,6 +2616,17 @@ dependencies = [
]
[[package]]
+name = "sha1"
+version = "0.10.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba"
+dependencies = [
+ "cfg-if",
+ "cpufeatures",
+ "digest",
+]
+
+[[package]]
name = "sha2"
version = "0.10.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2949,6 +2965,18 @@ dependencies = [
]
[[package]]
+name = "tokio-tungstenite"
+version = "0.20.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c"
+dependencies = [
+ "futures-util",
+ "log",
+ "tokio",
+ "tungstenite",
+]
+
+[[package]]
name = "tokio-util"
version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2998,7 +3026,7 @@ version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03"
dependencies = [
- "indexmap 2.1.0",
+ "indexmap",
"serde",
"serde_spanned",
"toml_datetime",
@@ -3079,6 +3107,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]]
+name = "tungstenite"
+version = "0.20.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9"
+dependencies = [
+ "byteorder",
+ "bytes",
+ "data-encoding",
+ "http",
+ "httparse",
+ "log",
+ "rand",
+ "sha1",
+ "thiserror",
+ "url",
+ "utf-8",
+]
+
+[[package]]
name = "typenum"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3170,6 +3217,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
[[package]]
+name = "utf-8"
+version = "0.7.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
+
+[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 1b0d230..96eeb3e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,7 +14,10 @@ members = [
resolver = "2"
[workspace.dependencies]
-rocket = { git = "https://github.com/SergioBenitez/Rocket", rev = "2cf38a5aa37fe046e46b03740835787f0396307b" }
+# rocket = { git = "https://github.com/SergioBenitez/Rocket", rev = "2cf38a5aa37fe046e46b03740835787f0396307b" }
+rocket = "0.5"
+rocket_ws = "0.1"
+
log = "0.4.20"
anyhow = "1.0.75"
tokio = { version = "1.35.0", features = ["full"] }
diff --git a/server/Cargo.toml b/server/Cargo.toml
index e6e6d20..a124876 100644
--- a/server/Cargo.toml
+++ b/server/Cargo.toml
@@ -32,6 +32,7 @@ tokio-util = { version = "0.7.10", features = ["io", "io-util"] }
markup = "0.15.0"
rocket = { workspace = true, features = ["secrets", "json"] }
+rocket_ws = { workspace = true }
[build-dependencies]
glob = "0.3.1"
diff --git a/server/src/routes/mod.rs b/server/src/routes/mod.rs
index d6c1e9f..e4d05e5 100644
--- a/server/src/routes/mod.rs
+++ b/server/src/routes/mod.rs
@@ -37,8 +37,11 @@ use ui::{
};
use userdata::{r_node_userdata, r_player_progress, r_player_watched};
+use self::streamsync::r_streamsync;
+
pub mod api;
pub mod stream;
+pub mod streamsync;
pub mod ui;
pub mod userdata;
@@ -85,6 +88,7 @@ pub fn build_rocket(database: DataAcid, federation: Federation) -> Rocket<Build>
routes![
r_home,
r_home_unpriv,
+ r_streamsync,
r_favicon,
r_item_assets,
r_all_items_filter,
diff --git a/server/src/routes/stream.rs b/server/src/routes/stream.rs
index 5c21a5a..11fd094 100644
--- a/server/src/routes/stream.rs
+++ b/server/src/routes/stream.rs
@@ -231,7 +231,7 @@ impl<'r> FromRequest<'r> for RequestRange {
match req.headers().get("range").next() {
Some(v) => match Self::from_hv(v) {
Ok(v) => rocket::outcome::Outcome::Success(v),
- Err(e) => rocket::outcome::Outcome::Failure((Status::BadRequest, e)),
+ Err(e) => rocket::outcome::Outcome::Error((Status::BadRequest, e)),
},
None => rocket::outcome::Outcome::Forward(Status::Ok),
}
diff --git a/server/src/routes/streamsync.rs b/server/src/routes/streamsync.rs
new file mode 100644
index 0000000..d4a4d7e
--- /dev/null
+++ b/server/src/routes/streamsync.rs
@@ -0,0 +1,11 @@
+use rocket::get;
+use rocket_ws::{Stream, WebSocket};
+
+#[get("/streamsync")]
+pub fn r_streamsync(ws: WebSocket) -> Stream!['static] {
+ Stream! { ws =>
+ for await message in ws {
+ yield message?;
+ }
+ }
+}
diff --git a/server/src/routes/ui/account/mod.rs b/server/src/routes/ui/account/mod.rs
index 8af92a0..eeafce1 100644
--- a/server/src/routes/ui/account/mod.rs
+++ b/server/src/routes/ui/account/mod.rs
@@ -186,12 +186,12 @@ pub fn r_account_login_post(
None => return Err(format_form_error(form)),
};
jar.add(
- Cookie::build(
+ Cookie::build((
"session",
login_logic(database, &form.username, &form.password, None, None)?,
- )
+ ))
.permanent()
- .finish(),
+ .build(),
);
Ok(Redirect::found(rocket::uri!(r_home())))
@@ -199,7 +199,7 @@ pub fn r_account_login_post(
#[post("/account/logout")]
pub fn r_account_logout_post(jar: &CookieJar) -> MyResult<Redirect> {
- jar.remove_private(Cookie::named("session"));
+ jar.remove_private(Cookie::build("session"));
Ok(Redirect::found(rocket::uri!(r_home())))
}
diff --git a/server/src/routes/ui/account/session/guard.rs b/server/src/routes/ui/account/session/guard.rs
index b2fd408..6969491 100644
--- a/server/src/routes/ui/account/session/guard.rs
+++ b/server/src/routes/ui/account/session/guard.rs
@@ -81,7 +81,7 @@ impl<'r> FromRequest<'r> for AdminSession {
if x.user.admin {
Outcome::Success(AdminSession(x))
} else {
- Outcome::Failure((
+ Outcome::Error((
Status::Unauthorized,
MyError(anyhow!("you are not an admin")),
))