Build Media Proxy
This commit is contained in:
parent
16bf825e14
commit
a1e57d874f
6 changed files with 142 additions and 34 deletions
139
Cargo.lock
generated
139
Cargo.lock
generated
|
@ -31,8 +31,11 @@ dependencies = [
|
|||
"futures-util",
|
||||
"http",
|
||||
"log",
|
||||
"rustls",
|
||||
"tokio-rustls",
|
||||
"trust-dns-proto",
|
||||
"trust-dns-resolver",
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -46,6 +49,7 @@ dependencies = [
|
|||
"actix-rt",
|
||||
"actix-service",
|
||||
"actix-threadpool",
|
||||
"actix-tls",
|
||||
"actix-utils",
|
||||
"base64 0.13.0",
|
||||
"bitflags",
|
||||
|
@ -89,7 +93,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "a60f9ba7c4e6df97f3aacb14bb5c0cd7d98a49dcbaed0d7f292912ad9a6a3ed2"
|
||||
dependencies = [
|
||||
"quote 1.0.7",
|
||||
"syn 1.0.48",
|
||||
"syn 1.0.50",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -189,6 +193,10 @@ dependencies = [
|
|||
"actix-service",
|
||||
"actix-utils",
|
||||
"futures-util",
|
||||
"rustls",
|
||||
"tokio-rustls",
|
||||
"webpki",
|
||||
"webpki-roots",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -241,6 +249,7 @@ dependencies = [
|
|||
"mime",
|
||||
"pin-project 1.0.2",
|
||||
"regex",
|
||||
"rustls",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_urlencoded 0.6.1",
|
||||
|
@ -258,7 +267,7 @@ checksum = "ad26f77093333e0e7c6ffe54ebe3582d908a104e448723eec6d43d08b07143fb"
|
|||
dependencies = [
|
||||
"proc-macro2 1.0.24",
|
||||
"quote 1.0.7",
|
||||
"syn 1.0.48",
|
||||
"syn 1.0.50",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -491,13 +500,13 @@ checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0"
|
|||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.41"
|
||||
version = "0.1.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b246867b8b3b6ae56035f1eb1ed557c1d8eae97f0d53696138a50fa0e3a3b8c0"
|
||||
checksum = "8d3a45e77e34375a7923b1e8febb049bb011f064714a8e17a1a616fef01da13d"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.24",
|
||||
"quote 1.0.7",
|
||||
"syn 1.0.48",
|
||||
"syn 1.0.50",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -531,6 +540,7 @@ dependencies = [
|
|||
"mime",
|
||||
"percent-encoding",
|
||||
"rand",
|
||||
"rustls",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_urlencoded 0.6.1",
|
||||
|
@ -828,7 +838,7 @@ checksum = "41cb0e6161ad61ed084a36ba71fbba9e3ac5aee3606fb607fe08da6acbcf3d8c"
|
|||
dependencies = [
|
||||
"proc-macro2 1.0.24",
|
||||
"quote 1.0.7",
|
||||
"syn 1.0.48",
|
||||
"syn 1.0.50",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -876,7 +886,7 @@ dependencies = [
|
|||
"heck",
|
||||
"proc-macro2 1.0.24",
|
||||
"quote 1.0.7",
|
||||
"syn 1.0.48",
|
||||
"syn 1.0.50",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1009,7 +1019,7 @@ dependencies = [
|
|||
"proc-macro-hack",
|
||||
"proc-macro2 1.0.24",
|
||||
"quote 1.0.7",
|
||||
"syn 1.0.48",
|
||||
"syn 1.0.50",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1391,7 +1401,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "libreddit"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
dependencies = [
|
||||
"actix-web",
|
||||
"askama",
|
||||
|
@ -1694,7 +1704,7 @@ checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895"
|
|||
dependencies = [
|
||||
"proc-macro2 1.0.24",
|
||||
"quote 1.0.7",
|
||||
"syn 1.0.48",
|
||||
"syn 1.0.50",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1705,7 +1715,7 @@ checksum = "f8e8d2bf0b23038a4424865103a4df472855692821aab4e4f5c3312d461d9e5f"
|
|||
dependencies = [
|
||||
"proc-macro2 1.0.24",
|
||||
"quote 1.0.7",
|
||||
"syn 1.0.48",
|
||||
"syn 1.0.50",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1896,6 +1906,21 @@ dependencies = [
|
|||
"quick-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ring"
|
||||
version = "0.16.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b72b84d47e8ec5a4f2872e8262b8f8256c5be1c938a7d6d3a867a3ba8f722f74"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"spin",
|
||||
"untrusted",
|
||||
"web-sys",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.18"
|
||||
|
@ -1911,6 +1936,19 @@ dependencies = [
|
|||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls"
|
||||
version = "0.18.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d1126dcf58e93cee7d098dbda643b5f92ed724f1f6a63007c1116eed6700c81"
|
||||
dependencies = [
|
||||
"base64 0.12.3",
|
||||
"log",
|
||||
"ring",
|
||||
"sct",
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.5"
|
||||
|
@ -1933,6 +1971,16 @@ version = "1.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||
|
||||
[[package]]
|
||||
name = "sct"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3042af939fca8c3453b7af0f1c66e533a15a86169e39de2657310ade8f98d3c"
|
||||
dependencies = [
|
||||
"ring",
|
||||
"untrusted",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.9.0"
|
||||
|
@ -1965,7 +2013,7 @@ checksum = "cbd1ae72adb44aab48f325a02444a5fc079349a8d804c1fc922aed3f7454c74e"
|
|||
dependencies = [
|
||||
"proc-macro2 1.0.24",
|
||||
"quote 1.0.7",
|
||||
"syn 1.0.48",
|
||||
"syn 1.0.50",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2081,16 +2129,22 @@ checksum = "7acad6f34eb9e8a259d3283d1e8c1d34d7415943d4895f65cc73813c7396fc85"
|
|||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
version = "0.3.16"
|
||||
version = "0.3.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fd8b795c389288baa5f355489c65e71fd48a02104600d15c4cfbc561e9e429d"
|
||||
checksum = "2c29947abdee2a218277abeca306f25789c938e500ea5a9d4b12a5a504466902"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.10",
|
||||
"cfg-if 1.0.0",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||
|
||||
[[package]]
|
||||
name = "spinning_top"
|
||||
version = "0.2.2"
|
||||
|
@ -2133,7 +2187,7 @@ dependencies = [
|
|||
"quote 1.0.7",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"syn 1.0.48",
|
||||
"syn 1.0.50",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2149,7 +2203,7 @@ dependencies = [
|
|||
"serde_derive",
|
||||
"serde_json",
|
||||
"sha1",
|
||||
"syn 1.0.48",
|
||||
"syn 1.0.50",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2199,9 +2253,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.48"
|
||||
version = "1.0.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac"
|
||||
checksum = "443b4178719c5a851e1bde36ce12da21d74a0e60b4d982ec3385a933c812f0f6"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.24",
|
||||
"quote 1.0.7",
|
||||
|
@ -2225,7 +2279,7 @@ checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56"
|
|||
dependencies = [
|
||||
"proc-macro2 1.0.24",
|
||||
"quote 1.0.7",
|
||||
"syn 1.0.48",
|
||||
"syn 1.0.50",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2292,7 +2346,7 @@ dependencies = [
|
|||
"proc-macro2 1.0.24",
|
||||
"quote 1.0.7",
|
||||
"standback",
|
||||
"syn 1.0.48",
|
||||
"syn 1.0.50",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2330,6 +2384,18 @@ dependencies = [
|
|||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-rustls"
|
||||
version = "0.14.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e12831b255bcfa39dc0436b01e19fea231a37db570686c06ee72c423479f889a"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"rustls",
|
||||
"tokio",
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-util"
|
||||
version = "0.3.1"
|
||||
|
@ -2374,7 +2440,7 @@ checksum = "80e0ccfc3378da0cce270c946b676a376943f5cd16aeba64568e7939806f4ada"
|
|||
dependencies = [
|
||||
"proc-macro2 1.0.24",
|
||||
"quote 1.0.7",
|
||||
"syn 1.0.48",
|
||||
"syn 1.0.50",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2503,6 +2569,12 @@ dependencies = [
|
|||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "untrusted"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
|
||||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.2.0"
|
||||
|
@ -2579,7 +2651,7 @@ dependencies = [
|
|||
"log",
|
||||
"proc-macro2 1.0.24",
|
||||
"quote 1.0.7",
|
||||
"syn 1.0.48",
|
||||
"syn 1.0.50",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
|
@ -2613,7 +2685,7 @@ checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe"
|
|||
dependencies = [
|
||||
"proc-macro2 1.0.24",
|
||||
"quote 1.0.7",
|
||||
"syn 1.0.48",
|
||||
"syn 1.0.50",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
@ -2634,6 +2706,25 @@ dependencies = [
|
|||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki"
|
||||
version = "0.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab146130f5f790d45f82aeeb09e55a256573373ec64409fc19a6fb82fb1032ae"
|
||||
dependencies = [
|
||||
"ring",
|
||||
"untrusted",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f20dea7535251981a9670857150d571846545088359b28e4951d350bdaf179f"
|
||||
dependencies = [
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wepoll-sys"
|
||||
version = "3.0.1"
|
||||
|
|
|
@ -3,12 +3,12 @@ name = "libreddit"
|
|||
description = " Alternative private front-end to Reddit"
|
||||
license = "AGPL-3.0"
|
||||
repository = "https://github.com/spikecodes/libreddit"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "3.2.0"
|
||||
actix-web = { version = "3.2.0", features = ["rustls"] }
|
||||
surf = "2.1.0"
|
||||
askama = "0.8.0"
|
||||
serde = "1.0.117"
|
||||
|
|
|
@ -6,7 +6,7 @@ Libre + Reddit = Libreddit
|
|||
|
||||
- 🚀 Fast: written in Rust for blazing fast speeds and safety
|
||||
- ☁️ Light: no javascript, no ads, no tracking
|
||||
- 🕵 Private: ~~all~~ most requests are proxied through the server (images are still loaded from Reddit)
|
||||
- 🕵 Private: all requests are proxied through the server, including media
|
||||
- 🔒 Safe: does not rely on Reddit's OAuth-requiring APIs
|
||||
- 📱 Responsive: works great on mobile!
|
||||
|
||||
|
@ -37,9 +37,9 @@ Think Invidious but for Reddit. Watch your cat videos without being watched.
|
|||
- [x] UTC post date
|
||||
- [x] Image thumbnails
|
||||
- [x] Embedded images
|
||||
- [ ] Proxied images
|
||||
- [x] Proxied images
|
||||
- [x] Reddit-hosted video
|
||||
- [ ] Proxied video
|
||||
- [x] Proxied video
|
||||
- [x] Users
|
||||
- [x] Username
|
||||
- [x] Karma
|
||||
|
|
|
@ -39,7 +39,7 @@ async fn main() -> std::io::Result<()> {
|
|||
}
|
||||
|
||||
// start http server
|
||||
println!("Running Libreddit on {}!", address);
|
||||
println!("Running Libreddit on {}!", address.clone());
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
|
@ -47,6 +47,8 @@ async fn main() -> std::io::Result<()> {
|
|||
.service(style)
|
||||
.service(favicon)
|
||||
.service(robots)
|
||||
// PROXY SERVICE
|
||||
.service(proxy::handler)
|
||||
// POST SERVICES
|
||||
.service(post::short)
|
||||
.service(post::page)
|
||||
|
@ -57,7 +59,8 @@ async fn main() -> std::io::Result<()> {
|
|||
// USER SERVICES
|
||||
.service(user::page)
|
||||
})
|
||||
.bind(address)?
|
||||
.bind(address.clone())
|
||||
.expect(format!("Cannot bind to the address: {}", address).as_str())
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
|
|
@ -77,15 +77,15 @@ async fn media(data: &serde_json::Value) -> String {
|
|||
let media: String = if !has_media {
|
||||
format!(r#"<h4 class="post_body"><a href="{u}">{u}</a></h4>"#, u = data["data"]["url"].as_str().unwrap())
|
||||
} else {
|
||||
format!(r#"<img class="post_image" src="{}.png"/>"#, data["data"]["url"].as_str().unwrap())
|
||||
format!(r#"<img class="post_image" src="/imageproxy/{}.png"/>"#, data["data"]["url"].as_str().unwrap())
|
||||
};
|
||||
|
||||
match post_hint {
|
||||
"hosted:video" => format!(
|
||||
r#"<video class="post_image" src="{}" controls/>"#,
|
||||
r#"<video class="post_image" src="/imageproxy/{}" controls/>"#,
|
||||
data["data"]["media"]["reddit_video"]["fallback_url"].as_str().unwrap()
|
||||
),
|
||||
"image" => format!(r#"<img class="post_image" src="{}"/>"#, data["data"]["url"].as_str().unwrap()),
|
||||
"image" => format!(r#"<img class="post_image" src="/imageproxy/{}"/>"#, data["data"]["url"].as_str().unwrap()),
|
||||
"self" => String::from(""),
|
||||
_ => media,
|
||||
}
|
||||
|
|
14
src/proxy.rs
14
src/proxy.rs
|
@ -0,0 +1,14 @@
|
|||
use actix_web::{get, web, HttpResponse, Result, client::Client, Error};
|
||||
|
||||
#[get("/imageproxy/{url:.*}")]
|
||||
async fn handler(web::Path(url): web::Path<String>) -> Result<HttpResponse> {
|
||||
dbg!("Proxy: ", &url);
|
||||
let client = Client::default();
|
||||
client.get(url)
|
||||
.send()
|
||||
.await
|
||||
.map_err(Error::from)
|
||||
.and_then(|res| {
|
||||
Ok(HttpResponse::build(res.status()).streaming(res))
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue