diff --git a/Cargo.lock b/Cargo.lock index cdb98ba..bd4c8a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2869,10 +2869,10 @@ dependencies = [ "async-std", "async-trait", "axum-test-helper", - "base64 0.21.5", "bincode", "bytes", "console-subscriber", + "data-encoding", "derive_more", "figment", "futures", diff --git a/Cargo.toml b/Cargo.toml index 76b3a67..b147d94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,7 +52,7 @@ multimap = "0.9.0" rhai = { version = "1.15.1", features = ["serde"] } serde_path_to_error = "0.1.14" uncased = "0.9.9" -base64 = "0.21.5" +data-encoding = "2.4.0" #format_serde_error = "0.3" [dev-dependencies] diff --git a/README.md b/README.md index 546bfcf..691378c 100644 --- a/README.md +++ b/README.md @@ -23,17 +23,17 @@ Remix your plex recommendations. ## Test server -There is a test server available, you can use it by base64 encoding your plex url and put it in front of replex.stream as a subdomain. +There is a test server available, you can use it by base32 encoding your plex url and put it in front of replex.stream as a subdomain. Example: -http://56.29.34.34:32400 -> aHR0cDovLzU2LjI5LjM0LjM0OjMyNDAwIA== -your test url would be: https://aHR0cDovLzU2LjI5LjM0LjM0OjMyNDAwIA==.replex.stream +http://56.29.34.34:32400 -> NB2HI4B2F4XTKNROGI4S4MZUFYZTIORTGI2DAMA= +your test url would be: https://NB2HI4B2F4XTKNROGI4S4MZUFYZTIORTGI2DAMA=.replex.stream Add the url to the "Custom server access URLs" in plex under network and disable remote access. Continue with [Mixed Rows](#mixed-rows) to continue setting up. -Base64 online encoding tool: https://emn178.github.io/online-tools/base64_encode.html +Base32 online encoding tool: https://emn178.github.io/online-tools/base32_encode.html ## Installation diff --git a/src/config.rs b/src/config.rs index 9a736fb..376f673 100644 --- a/src/config.rs +++ b/src/config.rs @@ -129,15 +129,27 @@ impl Config { pub fn dynamic(req: &salvo::Request) -> Figment { // dbg!(&req); - use base64::{Engine as _, alphabet, engine::{self, general_purpose}}; + // use base64::{Engine as _, alphabet, engine::{self, general_purpose}}; + // use base32::{decode, CrockfordBase32}; + // use crockford::decode; let host = req.headers().get("HOST").unwrap().to_str().unwrap(); let mut config = Config::figment(); if host.contains("replex.stream") { + use data_encoding::BASE32; let val: Vec<&str> = host.split(".replex.stream").collect(); + let owned_val = val[0].to_ascii_uppercase().to_owned(); + // dbg!(&val); // let mut decoded_host: String = String::new(); - let decoded_host = general_purpose::STANDARD - .decode(val[0]).unwrap(); + // let decoded_host = general_purpose::STANDARD + // .decode(val[0]).unwrap(); + // let decoded_host = decode(CrockfordBase32, &owned_val[..]); + // let decoded_host: String = crockford::decode(val[0].to_uppercase()).unwrap().to_string(); + let mut output = vec![0; BASE32.decode_len(owned_val.len()).unwrap()]; + let len = BASE32.decode_mut(owned_val.as_bytes(), &mut output).unwrap(); + // dbg!(std::str::from_utf8(&output[0 .. len]).unwrap()); config = config.join(("host", std::str::from_utf8(&decoded_host).unwrap())); + // config = config.join(("host", decoded_host)); + } config // Figment::new().merge(Env::prefixed("REPLEX_"))