This commit is contained in:
Simon
2025-09-03 12:15:08 +00:00
parent c3f994ccbb
commit ff18f3eb34
8 changed files with 279 additions and 132 deletions

41
src/proxy.rs Normal file
View File

@@ -0,0 +1,41 @@
use ntex::web::{self, HttpRequest};
use crate::proxies::sxyprn::SxyprnProxy;
use crate::util::{cache::VideoCache, requester::Requester};
use crate::proxies::*;
pub fn config(cfg: &mut web::ServiceConfig) {
cfg.service(
web::resource("/sxyprn/{endpoint}*")
.route(web::post().to(sxyprn))
.route(web::get().to(sxyprn)),
)
// .service(
// web::resource("/videos")
// // .route(web::get().to(videos_get))
// .route(web::post().to(videos_post)),
// )
;
}
async fn sxyprn(req: HttpRequest,
requester: web::types::State<Requester>,) -> Result<impl web::Responder, web::Error> {
let proxy = get_proxy(req.uri().to_string().split("/").collect::<Vec<&str>>()[2]).unwrap();
let endpoint = req.match_info().query("endpoint").to_string();
println!("/proxy/sxyprn: endpoint={:?}", endpoint);
let video_url = match proxy.get_video_url(endpoint, requester).await{
url if url != "" => url,
_ => "Error".to_string(),
};
Ok(web::HttpResponse::Found()
.header("Location", video_url)
.finish())
}
fn get_proxy(proxy: &str) -> Option<AnyProxy> {
match proxy {
"sxyprn" => Some(AnyProxy::Sxyprn(SxyprnProxy::new())),
_ => None,
}
}