logfix
All checks were successful
deploy / deploy (push) Successful in 1m3s

This commit is contained in:
Untone 2024-10-02 19:59:24 +03:00
parent 1953c13f01
commit 2c535e9848
2 changed files with 15 additions and 7 deletions

View File

@ -26,7 +26,7 @@ RUN cargo build --release
FROM rust
ENV RUST_BACKTRACE=full
ENV RUST_LOG=debug
ENV RUST_LOG=warn
RUN apt-get update && apt install -y openssl libssl-dev

View File

@ -2,7 +2,7 @@ use actix_multipart::Multipart;
use actix_web::{error::ErrorInternalServerError, web, HttpRequest, HttpResponse, Result};
use futures::StreamExt;
use mime_guess::MimeGuess;
use log::{info, warn};
use log::{info, warn, error};
use crate::app_state::AppState;
use crate::auth::{get_id_by_token, user_added_file};
@ -20,7 +20,8 @@ pub const MAX_WEEK_BYTES: u64 = 2 * 1024 * 1024 * 1024;
async fn serve_file(file_key: &str, state: &AppState) -> Result<HttpResponse, actix_web::Error> {
// Проверяем наличие файла в Storj S3
if !check_file_exists(&state.s3_client, &state.s3_bucket, file_key).await? {
return Err(ErrorInternalServerError("File not found in S3"));
warn!("Файл не найден в S3: {}", file_key);
return Ok(HttpResponse::NotFound().finish());
}
let checked_filekey = state.get_path(file_key).await.unwrap().unwrap();
@ -61,7 +62,7 @@ pub async fn upload_handler(
.get("Authorization")
.and_then(|header_value| header_value.to_str().ok());
if token.is_none() {
return Err(actix_web::error::ErrorUnauthorized("Unauthorized")); // Если токен отсутствует, возвращаем ошибку
return Err(actix_web::error::ErrorUnauthorized("Unauthorized")); // Если токен отстствует, возвращаем ошибку
}
let user_id = get_id_by_token(token.unwrap()).await?;
@ -95,7 +96,7 @@ pub async fn upload_handler(
// Квота превышена
}
// Инкрементируем квоту пользователя
// Инкреметируем квоту пользователя
let _ = state.increment_uploaded_bytes(&user_id, file_size).await?;
// Определяем правильное расширение и ключ для S3
@ -159,7 +160,7 @@ pub async fn proxy_handler(
{
info!("Запрошена миниатюра. Базовое имя файла: {}, Запрошенная ширина: {}", base_filename, requested_width);
// Находим ближайший подходящий размер
// аходим ближайший подходящий размер
let closest_width = find_closest_width(requested_width);
let thumbnail_key = format!("{}_{}", base_filename, closest_width);
info!("Ближайшая ширина: {}, Кюч миниатюры: {}", closest_width, thumbnail_key);
@ -206,5 +207,12 @@ pub async fn proxy_handler(
// Если запрошен целый файл
info!("Запрошен целый файл, возвращаем его");
serve_file(&requested_filekey, &state).await
info!("Проверка наличия файла в S3: {}", requested_filekey);
match serve_file(&requested_filekey, &state).await {
Ok(response) => Ok(response),
Err(e) => {
error!("Ошибка файла: {}", e);
Err(e)
}
}
}