Added video preview and http range support
Build and Publish / Build and Publish Docker Image (push) Successful in 5m11s

This commit is contained in:
Ultradesu
2026-08-08 10:19:47 +01:00
parent 1bee7a7940
commit f7a89b431d
8 changed files with 253 additions and 58 deletions
+23 -21
View File
@@ -370,7 +370,7 @@ async fn submit_feedback(
/// Serve media files for the client portal (no auth required, but only via token).
async fn portal_media(
_request: Request,
request: Request,
db: Database,
Path((token, media_id)): Path<(String, i64)>,
) -> cot::Result<Response> {
@@ -394,26 +394,28 @@ async fn portal_media(
}
}
match crate::uploads::read_db_file(&media.file_path).await {
Ok(data) => {
let content_type = match media.file_path.rsplit('.').next().unwrap_or("") {
"jpg" | "jpeg" => "image/jpeg",
"png" => "image/png",
"heic" | "heif" => "image/heic",
"webp" => "image/webp",
"mp4" => "video/mp4",
"mov" => "video/quicktime",
"avi" => "video/x-msvideo",
"mkv" => "video/x-matroska",
"webm" => "video/webm",
_ => "application/octet-stream",
};
let body = cot::Body::fixed(data);
let mut resp = Response::new(body);
resp.headers_mut()
.insert("content-type", content_type.parse().unwrap());
Ok(resp)
}
let range = request
.headers()
.get("range")
.and_then(|value| value.to_str().ok())
.map(str::to_owned);
match {
let content_type = match media.file_path.rsplit('.').next().unwrap_or("") {
"jpg" | "jpeg" => "image/jpeg",
"png" => "image/png",
"heic" | "heif" => "image/heic",
"webp" => "image/webp",
"mp4" => "video/mp4",
"mov" => "video/quicktime",
"avi" => "video/x-msvideo",
"mkv" => "video/x-matroska",
"webm" => "video/webm",
_ => "application/octet-stream",
};
crate::uploads::ranged_file_response(&media.file_path, content_type, range.as_deref()).await
} {
Ok(response) => Ok(response),
Err(err) => {
tracing::warn!(
target: "uploads",