heic-sys
Some checks failed
deploy / deploy (push) Failing after 6s

This commit is contained in:
2024-11-13 11:14:53 +03:00
parent fb1541f8e3
commit bc14d86018
9 changed files with 262 additions and 237 deletions

View File

@@ -6,6 +6,7 @@ use crate::app_state::AppState;
use crate::handlers::serve_file::serve_file;
use crate::s3_utils::{check_file_exists, load_file_from_s3, upload_to_s3};
use crate::thumbnail::{find_closest_width, parse_file_path, thumbdata_save};
use crate::lookup::{find_file_by_pattern, get_mime_type};
/// Обработчик для скачивания файла и генерации миниатюры, если она недоступна.
pub async fn proxy_handler(
@@ -30,24 +31,26 @@ pub async fn proxy_handler(
warn!("normalized to lowercase: {}", ext);
let filekey = format!("{}.{}", base_filename, &ext);
warn!("filekey: {}", filekey);
let content_type = match ext.as_str() {
"jpg" | "jpeg" => "image/jpeg",
"png" => "image/png",
"webp" => "image/webp",
"gif" => "image/gif",
"jfif" => "image/jpeg",
"heic" | "heif" => "image/heic",
"tif" | "tiff" => "image/tiff",
"mp3" => "audio/mpeg",
"wav" => "audio/x-wav",
"ogg" => "audio/ogg",
"aac" => "audio/aac",
"m4a" => "audio/m4a",
"flac" => "audio/flac",
_ => {
error!("unsupported file format");
return Err(ErrorInternalServerError("unsupported file format"));
},
let content_type = match get_mime_type(&ext) {
Some(mime) => mime.to_string(),
None => {
let mut redis = state.redis.clone();
match find_file_by_pattern(&mut redis, &base_filename).await {
Ok(Some(found_file)) => {
if let Some(found_ext) = found_file.split('.').last() {
get_mime_type(found_ext)
.unwrap_or("application/octet-stream")
.to_string()
} else {
"application/octet-stream".to_string()
}
}
_ => {
error!("unsupported file format");
return Err(ErrorInternalServerError("unsupported file format"));
}
}
}
};
warn!("content_type: {}", content_type);
@@ -148,7 +151,7 @@ pub async fn proxy_handler(
&state.bucket,
&filekey,
filedata.clone(),
content_type,
&content_type,
).await {
error!("Failed to upload to Storj: {} - Error: {}", filekey, e);
} else {
@@ -226,7 +229,7 @@ pub async fn proxy_handler(
&state.bucket,
&filekey,
filedata.clone(),
content_type,
&content_type,
)
.await {
warn!("cannot upload to storj: {}", e);