use ntex::http::Method; use ntex::http::header::LOCATION; use ntex::web::{self, HttpRequest}; use crate::util::requester::Requester; use crate::util::rule34video_resolve::{page_url, resolve_media_url}; /// The channel lists `/proxy/rule34video/{id}/{slug}` instead of resolving every /// video page while listing (which ran into the site's 429 limit): the page is /// read when the video is played, and the player is sent to its signed mp4. pub async fn redirect_to_media( req: HttpRequest, requester: web::types::State, ) -> impl web::Responder { let endpoint = req.match_info().query("endpoint").to_string(); let Some(page_url) = page_url(&endpoint) else { return web::HttpResponse::BadRequest().finish(); }; if req.method() == Method::HEAD { return web::HttpResponse::Ok().finish(); } let mut requester = requester.get_ref().clone(); match resolve_media_url(&mut requester, &page_url, None).await { Some(url) => web::HttpResponse::Found().header(LOCATION, url).finish(), None => web::HttpResponse::BadGateway().finish(), } }