clippy-fixes
This commit is contained in:
@@ -67,12 +67,6 @@ jobs:
|
||||
echo "total_coverage=$COVERAGE" >> $GITHUB_OUTPUT
|
||||
echo "Coverage: $COVERAGE"
|
||||
|
||||
- name: Create Coverage Badge
|
||||
run: |
|
||||
COVERAGE=$(cargo llvm-cov --summary | grep -oP 'coverage: \K[0-9.]+' || echo "0")
|
||||
echo "Покрытие тестами: $COVERAGE %" >> $GITHUB_OUTPUT
|
||||
continue-on-error: true
|
||||
|
||||
- name: Upload coverage HTML
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
|
||||
@@ -16,7 +16,6 @@ pub struct AppState {
|
||||
|
||||
const PATH_MAPPING_KEY: &str = "filepath_mapping"; // Ключ для хранения маппинга путей
|
||||
// Убираем TTL для квоты - она должна быть постоянной на пользователя
|
||||
const QUOTA_TTL: u64 = 0; // 0 означает отсутствие TTL
|
||||
|
||||
impl AppState {
|
||||
/// Инициализация нового состояния приложения.
|
||||
@@ -100,7 +99,7 @@ impl AppState {
|
||||
let _: () = redis
|
||||
.hset(PATH_MAPPING_KEY, filename.clone(), filepath)
|
||||
.await
|
||||
.expect(&format!("Failed to cache file {} in Redis", filename));
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
warn!("cached {} files", filelist.len());
|
||||
@@ -121,7 +120,7 @@ impl AppState {
|
||||
let _: () = redis
|
||||
.hset(PATH_MAPPING_KEY, filename, filepath)
|
||||
.await
|
||||
.expect(&format!("Failed to cache file {} in Redis", filename));
|
||||
.unwrap_or_else(|_| panic!("Failed to cache file {} in Redis", filename));
|
||||
}
|
||||
|
||||
/// создает или получает текущее значение квоты пользователя
|
||||
|
||||
13
src/auth.rs
13
src/auth.rs
@@ -69,15 +69,12 @@ pub async fn get_id_by_token(token: &str) -> Result<String, Box<dyn Error>> {
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(Box::new(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
"Invalid token response",
|
||||
)))
|
||||
Err(Box::new(std::io::Error::other("Invalid token response")))
|
||||
} else {
|
||||
Err(Box::new(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
format!("Request failed with status: {}", response.status()),
|
||||
)))
|
||||
Err(Box::new(std::io::Error::other(format!(
|
||||
"Request failed with status: {}",
|
||||
response.status()
|
||||
))))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,13 +52,9 @@ pub async fn get_shout_by_id(shout_id: i32) -> Result<Shout, Box<dyn Error>> {
|
||||
if let Some(shout) = core_response.data {
|
||||
return Ok(shout);
|
||||
}
|
||||
Err(Box::new(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
"Shout not found",
|
||||
)))
|
||||
Err(Box::new(std::io::Error::other("Shout not found")))
|
||||
} else {
|
||||
Err(Box::new(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
Err(Box::new(std::io::Error::other(
|
||||
response.status().to_string(),
|
||||
)))
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ pub async fn proxy_handler(
|
||||
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() {
|
||||
if let Some(found_ext) = found_file.split('.').next_back() {
|
||||
get_mime_type(found_ext)
|
||||
.unwrap_or("application/octet-stream")
|
||||
.to_string()
|
||||
@@ -80,7 +80,7 @@ pub async fn proxy_handler(
|
||||
warn!("Serving original file without resizing");
|
||||
serve_file(&stored_path, &state, shout_id).await
|
||||
} else {
|
||||
let closest: u32 = find_closest_width(requested_width as u32);
|
||||
let closest: u32 = find_closest_width(requested_width);
|
||||
warn!(
|
||||
"Calculated closest width: {} for requested: {}",
|
||||
closest, requested_width
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use actix_web::{web, HttpRequest, HttpResponse, Result};
|
||||
use log::{error, warn};
|
||||
use log::warn;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::app_state::AppState;
|
||||
|
||||
@@ -16,7 +16,7 @@ pub async fn serve_file(
|
||||
}
|
||||
|
||||
// Проверяем наличие файла в Storj S3
|
||||
let exists = check_file_exists(&state.storj_client, &state.bucket, &filepath).await?;
|
||||
let exists = check_file_exists(&state.storj_client, &state.bucket, filepath).await?;
|
||||
if !exists {
|
||||
return Err(ErrorInternalServerError(format!(
|
||||
"File {} not found in Storj",
|
||||
@@ -47,7 +47,7 @@ pub async fn serve_file(
|
||||
false => generate_overlay(shout_id, data.into_bytes()).await?,
|
||||
};
|
||||
|
||||
let mime_type = MimeGuess::from_path(&filepath).first_or_octet_stream();
|
||||
let mime_type = MimeGuess::from_path(filepath).first_or_octet_stream();
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type(mime_type.as_ref())
|
||||
|
||||
@@ -14,7 +14,7 @@ use actix_web::{
|
||||
web, App, HttpServer,
|
||||
};
|
||||
use app_state::AppState;
|
||||
use env_logger;
|
||||
|
||||
use handlers::{
|
||||
get_quota_handler, increase_quota_handler, proxy_handler, root_handler, set_quota_handler,
|
||||
upload_handler,
|
||||
|
||||
@@ -8,10 +8,7 @@ use std::{error::Error, io::Cursor};
|
||||
|
||||
use crate::core::get_shout_by_id;
|
||||
|
||||
pub async fn generate_overlay<'a>(
|
||||
shout_id: &'a str,
|
||||
filedata: Bytes,
|
||||
) -> Result<Bytes, Box<dyn Error>> {
|
||||
pub async fn generate_overlay(shout_id: &str, filedata: Bytes) -> Result<Bytes, Box<dyn Error>> {
|
||||
// Получаем shout из GraphQL
|
||||
let shout_id_int = shout_id.parse::<i32>().unwrap_or(0);
|
||||
match get_shout_by_id(shout_id_int).await {
|
||||
|
||||
@@ -58,14 +58,12 @@ pub fn parse_file_path(requested_path: &str) -> (String, u32, String) {
|
||||
}
|
||||
|
||||
// Проверка на старую ширину в путях, начинающихся с "unsafe"
|
||||
if path.starts_with("unsafe") && width == 0 {
|
||||
if path_parts.len() >= 2 {
|
||||
if let Some(old_width_str) = path_parts.get(1) {
|
||||
// Получаем второй элемент
|
||||
let old_width_str = old_width_str.trim_end_matches('x');
|
||||
if let Ok(w) = old_width_str.parse::<u32>() {
|
||||
width = w;
|
||||
}
|
||||
if path.starts_with("unsafe") && width == 0 && path_parts.len() >= 2 {
|
||||
if let Some(old_width_str) = path_parts.get(1) {
|
||||
// Получаем второй элемент
|
||||
let old_width_str = old_width_str.trim_end_matches('x');
|
||||
if let Ok(w) = old_width_str.parse::<u32>() {
|
||||
width = w;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,7 +127,7 @@ pub async fn thumbdata_save(
|
||||
) -> Result<(), actix_web::Error> {
|
||||
if content_type.starts_with("image") {
|
||||
warn!("original file name: {}", original_filename);
|
||||
let (base_filename, _, extension) = parse_file_path(&original_filename);
|
||||
let (base_filename, _, extension) = parse_file_path(original_filename);
|
||||
warn!("detected file extension: {}", extension);
|
||||
|
||||
// Для HEIC файлов просто сохраняем оригинал как миниатюру
|
||||
|
||||
Reference in New Issue
Block a user