update code level

This commit is contained in:
lychang
2026-03-25 14:38:21 +08:00
parent e05cf48063
commit 6b2d44ca78
8 changed files with 253 additions and 72 deletions

View File

@@ -10,30 +10,34 @@ use actix_web::{App, HttpResponse, HttpServer, web, middleware};
use std::fs;
use std::sync::Arc;
use tokio::time::{interval, Duration};
use tracing::{info, error, warn, debug};
use crate::models::AlbumsCache;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
// 初始化结构化日志
tracing_subscriber::fmt::init();
// 加载配置
let config = match config::Config::load() {
Ok(cfg) => cfg,
Err(e) => {
eprintln!("加载配置失败: {}", e);
error!("加载配置失败: {}", e);
std::process::exit(1);
}
};
println!("启动图片展示服务...");
println!("服务地址: http://{}", config.server_address());
info!("启动图片展示服务...");
info!("服务地址: http://{}", config.server_address());
// 初始化数据库
let db = match database::Database::new(&config).await {
Ok(db) => {
println!("数据库连接成功");
info!("数据库连接成功");
Arc::new(db)
}
Err(e) => {
eprintln!("数据库连接失败: {}", e);
error!("数据库连接失败: {}", e);
std::process::exit(1);
}
};
@@ -42,10 +46,10 @@ async fn main() -> std::io::Result<()> {
let config_clone = config.clone();
let db_clone = Arc::clone(&db);
tokio::spawn(async move {
println!("[后台任务] 开始扫描图片目录并导入新相册...");
info!("[后台任务] 开始扫描图片目录并导入新相册...");
match import::import_existing_data(&config_clone, db_clone).await {
Ok(_) => println!("[后台任务] 相册导入完成"),
Err(e) => eprintln!("[后台任务] 相册导入失败: {}", e),
Ok(_) => info!("[后台任务] 相册导入完成"),
Err(e) => error!("[后台任务] 相册导入失败: {}", e),
}
});