向nonebot对齐了一下日志输出

This commit is contained in:
2026-07-05 18:39:57 +08:00
parent 355cb36025
commit 1a645f9177
10 changed files with 260 additions and 169 deletions
+46 -28
View File
@@ -4,7 +4,9 @@ use crate::github::{fetch_last_hash, sync_data};
use crate::{CONFIG, PROVIDE, STATE, STORE, ending_point};
use anyhow::anyhow;
use assets_updater::core::export_pipeline::find_files;
use log::debug;
use futures::StreamExt;
use futures::stream::FuturesUnordered;
use log::{debug, info};
use std::fs;
pub async fn main() -> anyhow::Result<()> {
@@ -55,45 +57,61 @@ pub async fn main() -> anyhow::Result<()> {
let event = event.unwrap();
// event updated
info!("Event updated to {}", event.event_id);
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 {
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 {
let mut futures = FuturesUnordered::new();
for card in &cards {
futures.push(async {
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)?;
});
if file.is_file() && file.extension().map(|ext| ext == "png").unwrap_or(false) {
let new_filename = format!(
"{}_{}",
card.assetbundle_name,
file.file_name().unwrap().to_str().unwrap()
);
let new_file = cache_dir.join(new_filename);
fs::copy(&file, &new_file)?;
fs::remove_file(&file)?;
images.push(new_file);
let files = find_files(&dir.0)?;
let mut local_images = Vec::new();
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!(
"{}_{}",
card.assetbundle_name,
file.file_name().unwrap().to_str().unwrap()
);
let new_file = cache_dir.join(new_filename);
fs::copy(&file, &new_file)?;
fs::remove_file(&file)?;
local_images.push(new_file);
}
}
}
fs::remove_dir_all(dir.0)?;
fs::remove_dir_all(dir.0)?;
Ok::<_, anyhow::Error>((card.card_id, local_images))
});
}
let mut images = Vec::new();
while let Some(res) = futures.next().await {
images.push(res?);
}
images.sort_by(|a, b| b.0.cmp(&a.0)); // 大在前
let images: Vec<_> = images.into_iter().flat_map(|(_, sub)| sub).collect();
info!(
"In event {} collected {} images",
event.event_id,
images.len()
);
*PROVIDE.write().map_err(|e| anyhow!("{}", e))? = Some(FetchResult {
event_id: event.event_id,
card_paths: images,