清理线程

This commit is contained in:
2026-06-22 19:12:37 +08:00
parent 6829440c31
commit 03b6afade2
4 changed files with 82 additions and 15 deletions
+18 -3
View File
@@ -1,14 +1,15 @@
use crate::data::{FetchResult, State};
use crate::download::Downloader;
use crate::github::{fetch_last_hash, sync_data};
use crate::{CONFIG, PROVIDE, STATE, STORE};
use crate::{CONFIG, PROVIDE, STATE, STORE, ending_point};
use anyhow::anyhow;
use assets_updater::core::export_pipeline::find_files;
use std::fs;
use log::debug;
use std::fs;
pub async fn main() -> anyhow::Result<()> {
let current_hash = fetch_last_hash().await?;
ending_point!(ok);
let old_state = {
let mut l = STATE.read();
if l.is_err() {
@@ -33,7 +34,9 @@ pub async fn main() -> anyhow::Result<()> {
}
// hash updated
ending_point!(ok);
sync_data().await?;
ending_point!(ok);
let store = STORE.read().map_err(|e| anyhow!("{}", e))?;
let event = store.find_last_event();
if event
@@ -54,16 +57,28 @@ pub async fn main() -> anyhow::Result<()> {
let cards = store.find_cards_by_event(event.event_id);
drop(store);
ending_point!(ok);
let downloader = Downloader::new().await?;
ending_point!(ok);
let mut images = Vec::new();
let cache_dir = CONFIG.get().unwrap().cache_dir();
for card in cards {
debug!("Pulling card {} from bundle {}", card.card_id, card.assetbundle_name);
ending_point!(ok);
debug!(
"Pulling card {} from bundle {}",
card.card_id, card.assetbundle_name
);
let dir = downloader
.pull(&format!("character/member/{}", card.assetbundle_name))
.await?;
ending_point!(ok_with {
fs::remove_dir_all(dir.0)?;
});
let files = find_files(&dir.0)?;
for file in files {
ending_point!(ok_with {
fs::remove_dir_all(dir.0)?;
});
if file.is_file() && file.extension().map(|ext| ext == "png").unwrap_or(false) {
let new_filename = format!(
"{}_{}",