1ffe0ffa9f
Offline Ultimate Team backend — game-independent REST API. - 19 API endpoints: auth, profiles, clubs, cards, packs, squads, objectives, SBCs, match rewards, NPC market, statistics - Axum + SQLite + SQLx with full migrations - Weighted pack generator, SBC validation engine - JSON-driven mod data (cards, packs, objectives, SBCs) - 5 integration tests passing Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
25 lines
851 B
Rust
25 lines
851 B
Rust
use anyhow::{Context, Result};
|
|
use serde::de::DeserializeOwned;
|
|
use std::path::Path;
|
|
|
|
#[allow(dead_code)]
|
|
/// Generic loader for JSON arrays from a directory.
|
|
pub fn load_json_dir<T: DeserializeOwned>(dir: &Path) -> Result<Vec<T>> {
|
|
let mut items = Vec::new();
|
|
if !dir.exists() {
|
|
return Ok(items);
|
|
}
|
|
for entry in std::fs::read_dir(dir).with_context(|| format!("reading dir {dir:?}"))? {
|
|
let entry = entry?;
|
|
let path = entry.path();
|
|
if path.extension().map(|e| e == "json").unwrap_or(false) {
|
|
let content =
|
|
std::fs::read_to_string(&path).with_context(|| format!("reading {path:?}"))?;
|
|
let batch: Vec<T> =
|
|
serde_json::from_str(&content).with_context(|| format!("parsing {path:?}"))?;
|
|
items.extend(batch);
|
|
}
|
|
}
|
|
Ok(items)
|
|
}
|