mirror of
https://github.com/euzu/tuliprox.git
synced 2026-10-21 07:12:25 +02:00
fixed hls api
This commit is contained in:
@@ -25,13 +25,10 @@ struct HlsApiPathParams {
|
||||
token: String,
|
||||
}
|
||||
|
||||
fn hls_response(hls_content: String, cookie: Option<String>) -> impl IntoResponse + Send {
|
||||
fn hls_response(hls_content: String) -> impl IntoResponse + Send {
|
||||
let mut builder = axum::response::Response::builder()
|
||||
.status(axum::http::StatusCode::OK)
|
||||
.header(axum::http::header::CONTENT_TYPE, "application/x-mpegurl");
|
||||
if let Some(cookie) = cookie {
|
||||
builder = builder.header(axum::http::header::SET_COOKIE, cookie);
|
||||
}
|
||||
builder.body(hls_content)
|
||||
.unwrap()
|
||||
.into_response()
|
||||
@@ -85,7 +82,7 @@ pub(in crate::api) async fn handle_hls_stream_request(
|
||||
user_token: session_token.as_deref(),
|
||||
};
|
||||
let hls_content = rewrite_hls(user, &rewrite_hls_props);
|
||||
hls_response(hls_content, session_token).into_response()
|
||||
hls_response(hls_content).into_response()
|
||||
}
|
||||
Err(err) => {
|
||||
error!("Failed to download m3u8 {}", sanitize_sensitive_info(err.to_string().as_str()));
|
||||
|
||||
@@ -534,7 +534,11 @@ impl ApiProxyConfig {
|
||||
return Some((credentials.clone(), target_name.to_string()));
|
||||
}
|
||||
}
|
||||
debug!("Could not find any target for user {username}");
|
||||
if log::log_enabled!(log::Level::Debug) {
|
||||
if !username.eq("api") {
|
||||
debug!("Could not find any target for user {username}");
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
|
||||
@@ -3,19 +3,23 @@ use crate::utils::{CONSTANTS, HLS_PREFIX};
|
||||
use crate::utils::{deobfuscate_text, obfuscate_text};
|
||||
use std::str;
|
||||
|
||||
const TOKEN_SEPARATOR: char = '\x1F';
|
||||
|
||||
fn create_hls_session_token_and_url(secret: &[u8], session_token: &str, stream_url: &str) -> Option<String> {
|
||||
if let Ok(cookie_value) = obfuscate_text(secret, &format!("{session_token}{stream_url}")) {
|
||||
if let Ok(cookie_value) = obfuscate_text(secret, &format!("{session_token}{TOKEN_SEPARATOR}{stream_url}")) {
|
||||
return Some(cookie_value);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
const TOKEN_LEN: usize = 6;
|
||||
pub fn get_hls_session_token_and_url_from_token(secret: &[u8], token: &str) -> Option<(Option<String>, String)> {
|
||||
if let Ok(decrypted) = deobfuscate_text(secret, token) {
|
||||
let session_token: String = decrypted.chars().take(TOKEN_LEN).collect();
|
||||
let stream_url: String = decrypted.chars().skip(TOKEN_LEN).collect();
|
||||
return Some((Some(session_token), stream_url));
|
||||
let parts: Vec<&str> = decrypted.split(TOKEN_SEPARATOR).collect();
|
||||
if !parts.is_empty() && parts.len() == 2 {
|
||||
let session_token: String = parts[0].to_string();
|
||||
let stream_url: String = parts[1].to_string();
|
||||
return Some((Some(session_token), stream_url));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user