fixed hls api

This commit is contained in:
euzu
2025-06-09 13:00:37 +02:00
parent f87e308660
commit d8daefb452
3 changed files with 16 additions and 11 deletions
+2 -5
View File
@@ -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()));
+5 -1
View File
@@ -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
}
+9 -5
View File
@@ -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
}