update code level

This commit is contained in:
lychang
2026-05-13 21:08:04 +08:00
parent b5df61c78a
commit 8f214b587b
5 changed files with 9 additions and 28 deletions

View File

@@ -39,7 +39,6 @@ impl ImageProcessor {
pub fn new(config: StorageConfig) -> Self {
// 确保目录存在
fs::create_dir_all(&config.images_dir).unwrap_or(());
fs::create_dir_all(&config.thumbnails_dir).unwrap_or(());
Self { config }
}
@@ -66,13 +65,7 @@ impl ImageProcessor {
let (width, height) = img.dimensions();
let file_size = image_data.len() as i64;
// 生成缩略图
let thumbnail_path = self
.config
.thumbnails_dir
.join(format!("thumb_{}", new_filename));
self.generate_thumbnail(&img, &thumbnail_path, 0, 0)?;
// 不再生成缩略图,直接返回原图信息
Ok(ImageInfo {
id: image_id,
filename: new_filename,
@@ -84,23 +77,15 @@ impl ImageProcessor {
}
/// 生成缩略图并保存到指定路径(使用统一尺寸)
/// 此功能已被移除,直接返回成功
pub fn generate_thumbnail(
&self,
img: &image::DynamicImage,
output_path: &Path,
_img: &image::DynamicImage,
_output_path: &Path,
_max_width: u32,
_max_height: u32,
) -> Result<(), ImageProcessorError> {
// 使用统一的缩略图尺寸(400x300,保持宽高比)
let thumbnail = img.thumbnail(400, 300);
// 确保输出目录存在
if let Some(parent) = output_path.parent() {
fs::create_dir_all(parent)?;
}
thumbnail.save_with_format(output_path, ImageFormat::Jpeg)?;
// 缩略图功能已移除,此函数不再执行任何操作
Ok(())
}
@@ -186,4 +171,4 @@ pub struct ImageInfo {
pub height: i32,
pub file_size: i64,
pub mime_type: String,
}
}