diff --git a/src/app_state.rs b/src/app_state.rs index 76d1153..effbad4 100644 --- a/src/app_state.rs +++ b/src/app_state.rs @@ -1,5 +1,3 @@ -// app_state.rs - use actix_web::error::ErrorInternalServerError; use aws_config::BehaviorVersion; use aws_sdk_s3::{config::Credentials, Client as S3Client}; diff --git a/src/auth.rs b/src/auth.rs index 4fc0119..7d4cc20 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1,5 +1,3 @@ -// auth.rs - use actix_web::error::ErrorInternalServerError; use redis::{aio::MultiplexedConnection, AsyncCommands}; use reqwest::header::{HeaderMap, HeaderValue, CONTENT_TYPE}; diff --git a/src/handlers.rs b/src/handlers.rs index cb9f541..55b3990 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -1,4 +1,7 @@ -// handlers.rs +use actix_multipart::Multipart; +use actix_web::{error::ErrorInternalServerError, web, HttpRequest, HttpResponse, Result}; +use futures::StreamExt; +use mime_guess::MimeGuess; use crate::app_state::AppState; use crate::auth::{get_id_by_token, user_added_file}; @@ -8,13 +11,9 @@ use crate::s3_utils::{ use crate::thumbnail::{ find_closest_width, generate_thumbnails, parse_thumbnail_request, ALLOWED_THUMBNAIL_WIDTHS, }; -use actix_multipart::Multipart; -use actix_web::error::ErrorInternalServerError; -use actix_web::{web, HttpRequest, HttpResponse, Result}; -use futures::StreamExt; -use mime_guess::MimeGuess; -pub const MAX_WEEK_BYTES: u64 = 2 * 1024 * 1024 * 1024; // Лимит квоты на пользователя: 2 ГБ в неделю +// Лимит квоты на пользователя: 2 ГБ в неделю +pub const MAX_WEEK_BYTES: u64 = 2 * 1024 * 1024 * 1024; /// Функция для обслуживания файла по заданному пути. async fn serve_file(file_key: &str, state: &AppState) -> Result { @@ -160,7 +159,7 @@ pub async fn proxy_handler( let thumbnails_bytes = generate_thumbnails(&image, &ALLOWED_THUMBNAIL_WIDTHS).await?; let thumbnail_bytes = thumbnails_bytes[&closest_width].clone(); - + // Загружаем миниатюру в S3 upload_to_s3( &state.s3_client, diff --git a/src/main.rs b/src/main.rs index 56c9bb6..0a65b23 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ async fn main() -> std::io::Result<()> { let app_state = AppState::new().await; let app_state_clone = app_state.clone(); - + // Используем spawn_blocking для работы, которая не совместима с Send spawn_blocking(move || { let rt = tokio::runtime::Handle::current(); @@ -34,4 +34,4 @@ async fn main() -> std::io::Result<()> { .bind("127.0.0.1:8080")? .run() .await -} \ No newline at end of file +} diff --git a/src/s3_utils.rs b/src/s3_utils.rs index 1600111..50be364 100644 --- a/src/s3_utils.rs +++ b/src/s3_utils.rs @@ -1,8 +1,7 @@ -use std::str::FromStr; - use actix_web::error::ErrorInternalServerError; use aws_sdk_s3::{error::SdkError, primitives::ByteStream, Client as S3Client}; use mime_guess::mime; +use std::str::FromStr; /// Загружает файл в S3 хранилище. pub async fn upload_to_s3( diff --git a/src/thumbnail.rs b/src/thumbnail.rs index 44d36da..a61b71d 100644 --- a/src/thumbnail.rs +++ b/src/thumbnail.rs @@ -1,5 +1,3 @@ -// thumbnail.rs - use actix_web::error::ErrorInternalServerError; use image::{imageops::FilterType, DynamicImage}; use std::{collections::HashMap, io::Cursor};