Compare commits
No commits in common. "93ec52f555bcfdb44b77cd7f263af4f34fed4d38" and "674eba3fd0c4c82c14b0d28468b2c6dd43d74bad" have entirely different histories.
93ec52f555
...
674eba3fd0
5 changed files with 348 additions and 299 deletions
591
Cargo.lock
generated
591
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -9,7 +9,7 @@ camino = "1.2.2"
|
|||
clap = { version = "4.5.53", features = ["derive"] }
|
||||
directories = "6.0.0"
|
||||
fluent-templates = "0.13.2"
|
||||
reqwest = { version = "0.12.28", default-features = false, features = [
|
||||
reqwest = { version = "0.12.26", default-features = false, features = [
|
||||
"brotli",
|
||||
"http2",
|
||||
"gzip",
|
||||
|
|
@ -21,7 +21,7 @@ serde = { version = "1.0.228", default-features = false, features = [
|
|||
"derive",
|
||||
"std",
|
||||
] }
|
||||
serde_json = "1.0.148"
|
||||
serde_json = "1.0.147"
|
||||
strum = { version = "0.27.2", features = ["derive"] }
|
||||
tokio = { version = "1.48.0", default-features = false, features = [
|
||||
"fs",
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ pub enum EditionCode {
|
|||
/// Sword and Shield
|
||||
Ssh,
|
||||
/// SV Promos
|
||||
#[serde(alias = "PR-SV")]
|
||||
Svp,
|
||||
/// Scarlet and Violet
|
||||
Svi,
|
||||
|
|
@ -53,8 +52,6 @@ pub enum EditionCode {
|
|||
Blk,
|
||||
/// White Flare
|
||||
Wht,
|
||||
/// Mega Evolution Promos
|
||||
Mep,
|
||||
/// Mega Evolution
|
||||
Meg,
|
||||
/// Phantasmal Flames
|
||||
|
|
@ -82,7 +79,6 @@ impl EditionCode {
|
|||
EditionCode::Dri => "SV10",
|
||||
EditionCode::Blk => "SV10pt5ZSV",
|
||||
EditionCode::Wht => "SV10pt5RSV",
|
||||
EditionCode::Mep => "MEP",
|
||||
EditionCode::Meg => "MEG1",
|
||||
EditionCode::Pfl => "MEG2",
|
||||
}
|
||||
|
|
@ -108,7 +104,6 @@ impl EditionCode {
|
|||
EditionCode::Dri => "destined-rivals",
|
||||
EditionCode::Blk | EditionCode::Wht => "black-white",
|
||||
EditionCode::Meg => "mega-evolution",
|
||||
EditionCode::Mep => "mega-evolution-promos",
|
||||
EditionCode::Pfl => "phantasmal-flames",
|
||||
}
|
||||
}
|
||||
|
|
@ -133,7 +128,7 @@ impl EditionCode {
|
|||
| EditionCode::Dri
|
||||
| EditionCode::Blk
|
||||
| EditionCode::Wht => EditionBlock::Sv,
|
||||
EditionCode::Meg | EditionCode::Mep | EditionCode::Pfl => EditionBlock::Meg,
|
||||
EditionCode::Meg | EditionCode::Pfl => EditionBlock::Meg,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use tokio_stream::StreamExt;
|
|||
use tokio_util::io::StreamReader;
|
||||
use tracing::debug;
|
||||
|
||||
use super::models::RawIndex;
|
||||
use super::models::Index;
|
||||
use crate::directories::data_cache_directory;
|
||||
|
||||
/// Client to download data from mallie.io
|
||||
|
|
@ -41,12 +41,12 @@ impl Client {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn load_tcgl_index(&self) -> Result<RawIndex> {
|
||||
async fn load_tcgl_index(&self) -> Result<Index> {
|
||||
let file_path = self.data_cache_directory.join("tcgl_index.json");
|
||||
let index = tokio::fs::read_to_string(&file_path)
|
||||
.await
|
||||
.with_context(|| format!("Failed to read {file_path}"))?;
|
||||
let index: RawIndex =
|
||||
let index: Index =
|
||||
serde_json::from_str(&index).with_context(|| format!("Couldn't parse {file_path}"))?;
|
||||
Ok(index)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,15 +2,13 @@
|
|||
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
|
||||
use anyhow::Context;
|
||||
use serde::{Deserialize, de};
|
||||
use tracing::warn;
|
||||
|
||||
use crate::editions::EditionCode;
|
||||
|
||||
pub type RawIndex = HashMap<Lang, HashMap<String, RawEdition>>;
|
||||
pub type Index = HashMap<Lang, Vec<Edition>>;
|
||||
pub type Index = HashMap<Lang, HashMap<String, Edition>>;
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, PartialEq, Hash)]
|
||||
pub enum Lang {
|
||||
|
|
@ -31,17 +29,12 @@ pub enum Lang {
|
|||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct RawEdition {
|
||||
pub struct Edition {
|
||||
path: String,
|
||||
#[serde(deserialize_with = "deserialize_edition_code")]
|
||||
abbr: Option<EditionCode>,
|
||||
}
|
||||
|
||||
pub struct Edition {
|
||||
path: String,
|
||||
abbr: EditionCode,
|
||||
}
|
||||
|
||||
fn deserialize_edition_code<'de, D>(deserializer: D) -> Result<Option<EditionCode>, D::Error>
|
||||
where
|
||||
D: de::Deserializer<'de>,
|
||||
|
|
@ -52,25 +45,11 @@ where
|
|||
return Ok(None);
|
||||
}
|
||||
|
||||
let result = serde_json::from_str::<EditionCode>(&format!("\"{buf}\""))
|
||||
.with_context(|| format!("couldn't deserialize edition code {buf}"))
|
||||
.inspect_err(|e| warn!("{e}"));
|
||||
Ok(result.ok())
|
||||
}
|
||||
let buf = if buf.to_uppercase() == "PR-SV" {
|
||||
"SVP".into()
|
||||
} else {
|
||||
buf
|
||||
};
|
||||
|
||||
fn filter_invalid_editions(index: RawIndex) -> Index {
|
||||
index
|
||||
.into_iter()
|
||||
.map(|(k, v)| {
|
||||
let v = v
|
||||
.into_values()
|
||||
.map(|e| match e.abbr {
|
||||
Some(abbr) => Some(Edition { path: e.path, abbr }),
|
||||
None => None,
|
||||
})
|
||||
.flatten()
|
||||
.collect();
|
||||
(k, v)
|
||||
})
|
||||
.collect()
|
||||
Ok(EditionCode::from_str(&buf).ok())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue