This commit is contained in:
2026-08-08 00:48:05 +08:00
parent 1a645f9177
commit b56f3fa40a
7 changed files with 171 additions and 46 deletions
+27 -9
View File
@@ -1,4 +1,4 @@
use crate::data::{FetchResult, State};
use crate::data::{FetchResult, FetchResultCard, State};
use crate::download::Downloader;
use crate::github::{fetch_last_hash, sync_data};
use crate::{CONFIG, PROVIDE, STATE, STORE, ending_point};
@@ -70,7 +70,7 @@ pub async fn main() -> anyhow::Result<()> {
ending_point!(ok);
debug!(
"Pulling card {} from bundle {}",
card.card_id, card.assetbundle_name
card.id, card.assetbundle_name
);
let dir = downloader
.pull(&format!("character/member/{}", card.assetbundle_name))
@@ -97,25 +97,43 @@ pub async fn main() -> anyhow::Result<()> {
}
}
fs::remove_dir_all(dir.0)?;
Ok::<_, anyhow::Error>((card.card_id, local_images))
Ok::<_, anyhow::Error>((card.clone(), 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();
images.sort_by(|a, b| a.0.id.cmp(&b.0.id)); // 在前
let images: Vec<_> = images
.into_iter()
.map(|(card, path)| FetchResultCard {
text: format!(
"#{id} {attr}{rarity} {skill} [{prefix}]{name}",
id = card.id,
attr = card.attr_short_text(),
rarity = card.rarity_short_text(),
skill = card
.skill_id_short().map(|s| format!("({})", s))
.unwrap_or_default(),
prefix = card.prefix,
name = card.character_name()
),
path,
})
.collect();
info!(
"In event {} collected {} images",
"In event {} collected {} cards",
event.event_id,
images.len()
);
*PROVIDE.write().map_err(|e| anyhow!("{}", e))? = Some(FetchResult {
let result = FetchResult {
event_id: event.event_id,
card_paths: images,
});
cards: images,
};
debug!("Providing result: {:?}", result);
*PROVIDE.write().map_err(|e| anyhow!("{}", e))? = Some(result);
let mut state = STATE.write().map_err(|e| anyhow!("{}", e))?;
state.git_hash = Some(current_hash);
state.event_id = Some(event.event_id);