First commit

This commit is contained in:
video-prize-ranch
2022-04-11 19:34:46 -04:00
commit 8b89d9c66b
4 changed files with 1462 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
/target
Generated
+1401
View File
File diff suppressed because it is too large Load Diff
+10
View File
@@ -0,0 +1,10 @@
[package]
name = "librarian-proxy"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
actix-web = { version = "4" }
awc = { version = "3", features = ["rustls"] }
+50
View File
@@ -0,0 +1,50 @@
use actix_web::{error, web, App, Error, HttpResponse, HttpServer};
use awc::Client;
async fn forward(payload: web::Payload, path: web::Path<String>) -> Result<HttpResponse, Error> {
let cdn_url = "https://cdn.odysee.live/";
let url = cdn_url.to_owned() + &path;
let client = Client::default();
println!("{}", url);
let forwarded_req = client
.get(url)
.insert_header((
"User-Agent",
"Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0",
))
.insert_header(("Origin", "https://odysee.com"))
.insert_header(("Referer", "https://odysee.com/"))
.no_decompress();
let res = forwarded_req
.send_stream(payload)
.await
.map_err(error::ErrorInternalServerError)?;
let mut client_resp = HttpResponse::build(res.status());
// Remove `Connection` as per
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection#Directives
for (header_name, header_value) in res.headers().iter().filter(|(h, _)| *h != "connection") {
client_resp.insert_header((header_name.clone(), header_value.clone()));
}
client_resp.insert_header(("Access-Control-Allow-Origin", "*"));
Ok(client_resp.streaming(res))
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(move || {
App::new()
//.app_data(web::Data::new(Client::default()))
//.app_data(web::Data::new(forward_url.clone()))
.route("/live/{path:.*}", web::get().to(forward))
})
.bind("0.0.0.0:3001")?
.workers(4)
.run()
.await
}