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