Prepare large paid files on disk and stream peer responses in bounded chunks

This commit is contained in:
archipelago
2026-10-06 05:31:19 -04:00
parent 051dc7e3df
commit 2fee0339cb
5 changed files with 588 additions and 68 deletions
+19 -4
View File
@@ -139,10 +139,23 @@ impl ApiHandler {
}
// Parse Range header for streaming support
let range = headers
.get("range")
.and_then(|v| v.to_str().ok())
.and_then(content_server::parse_range_header);
let range = match headers.get("range") {
None => None,
Some(value) => match value
.to_str()
.ok()
.and_then(content_server::parse_range_header)
{
Some(range) => Some(range),
None => {
return Ok(build_response(
StatusCode::BAD_REQUEST,
"text/plain",
hyper::Body::from("Invalid byte range"),
))
}
},
};
match content_server::serve_content(
&config.data_dir,
@@ -155,6 +168,7 @@ impl ApiHandler {
)
.await
{
Ok(content_server::ServeResult::Stream(body)) => body.into_response(),
Ok(content_server::ServeResult::Ok(bytes, mime_type)) => {
let len = bytes.len();
Ok(Response::builder()
@@ -496,6 +510,7 @@ impl ApiHandler {
}
match content_server::serve_content_preview(&config.data_dir, content_id).await {
Ok(content_server::PreviewResult::Stream(body)) => body.into_response(),
Ok(content_server::PreviewResult::FullContent(bytes, mime_type)) => {
let len = bytes.len();
Ok(Response::builder()