update code level

This commit is contained in:
lychang
2026-03-25 04:49:36 +08:00
parent 8a7156128b
commit af15d9f3d1
9 changed files with 337 additions and 80 deletions

View File

@@ -6,7 +6,7 @@ mod models;
mod routes;
use actix_files as afs;
use actix_web::{App, HttpResponse, HttpServer, web};
use actix_web::{App, HttpResponse, HttpServer, web, middleware};
use std::fs;
use std::sync::Arc;
@@ -74,6 +74,10 @@ async fn main() -> std::io::Result<()> {
HttpServer::new(move || {
App::new()
// 启用压缩中间件
.wrap(middleware::Compress::default())
// 启用日志中间件
.wrap(middleware::Logger::default())
.app_data(web::Data::new(Arc::clone(&db)))
.app_data(web::Data::new(Arc::clone(&image_processor)))
// API路由
@@ -92,8 +96,12 @@ async fn main() -> std::io::Result<()> {
.route("/api/favorites", web::post().to(routes::add_favorite))
.route("/api/favorites/{id}", web::delete().to(routes::remove_favorite))
.route("/api/favorites/image/{id}", web::delete().to(routes::remove_favorite_by_image))
// 静态文件服务
.service(afs::Files::new("/assets", "./assets").show_files_listing())
// 静态文件服务 - 启用缓存
.service(afs::Files::new("/assets", "./assets")
.show_files_listing()
.prefer_utf8(true)
.use_last_modified(true)
.use_etag(true))
// HTML页面路由
.route(
"/",