refactor: 用更 idiomatic 的方式改写一些代码 (#54)

* refactor: Config 采用 arc_swap 而非锁

* refactor: 改进 config 的检查,及其他一些细微优化

* refactor: 不再拆分 lib.rs 和 main.rs
This commit is contained in:
idlercloud
2024-04-04 18:39:41 +08:00
committed by GitHub
parent 2521fe932b
commit 4ba23ce8fc
12 changed files with 279 additions and 255 deletions

View File

@@ -21,13 +21,10 @@ use crate::config::CONFIG;
pub static TEMPLATE: Lazy<handlebars::Handlebars> = Lazy::new(|| {
let mut handlebars = handlebars::Handlebars::new();
let config = CONFIG.lock().unwrap();
handlebars
.register_template_string("video", config.video_name.clone())
.unwrap();
handlebars
.register_template_string("page", config.page_name.clone())
.register_template_string("video", &CONFIG.video_name)
.unwrap();
handlebars.register_template_string("page", &CONFIG.page_name).unwrap();
handlebars
});
@@ -48,13 +45,13 @@ pub struct NFOSerializer<'a>(pub ModelWrapper<'a>, pub NFOMode);
/// 根据获得的收藏夹信息,插入或更新数据库中的收藏夹,并返回收藏夹对象
pub async fn handle_favorite_info(
info: &FavoriteListInfo,
path: &str,
path: &Path,
connection: &DatabaseConnection,
) -> Result<favorite::Model> {
favorite::Entity::insert(favorite::ActiveModel {
f_id: Set(info.id),
name: Set(info.title.to_string()),
path: Set(path.to_owned()),
name: Set(info.title.clone()),
path: Set(path.to_string_lossy().to_string()),
..Default::default()
})
.on_conflict(