56 lines
1.6 KiB
Rust
56 lines
1.6 KiB
Rust
use chrono::NaiveDate;
|
|
use serde::Deserialize;
|
|
|
|
pub struct AppState {
|
|
pub mp_tracks: Vec<Track>,
|
|
pub p_tracks: Vec<Track>,
|
|
pub website_news: Vec<WebsiteArticle>,
|
|
pub bibou_quotes: Vec<String>,
|
|
}
|
|
|
|
impl AppState {
|
|
pub async fn try_new() -> Self {
|
|
Self {
|
|
mp_tracks: serde_json::from_str(
|
|
&std::fs::read_to_string("content/mp-tracks.json")
|
|
.expect("mp-tracks.json non trouvé"),
|
|
)
|
|
.expect("JSON invalide"),
|
|
p_tracks: serde_json::from_str(
|
|
&std::fs::read_to_string("content/p-tracks.json")
|
|
.expect("p-tracks.json non trouvé"),
|
|
)
|
|
.expect("JSON invalide"),
|
|
website_news: {
|
|
let mut news: Vec<WebsiteArticle> = serde_json::from_str(
|
|
&std::fs::read_to_string("content/web-articles.json")
|
|
.expect("web-articles.json non trouvé"),
|
|
)
|
|
.expect("JSON invalide");
|
|
|
|
news.sort_by(|a, b| b.date.cmp(&a.date));
|
|
|
|
news
|
|
},
|
|
bibou_quotes: serde_json::from_str(
|
|
&std::fs::read_to_string("content/bibou-quotes.json")
|
|
.expect("bibou-quotes.json non trouvé"),
|
|
)
|
|
.expect("JSON invalide"),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct Track {
|
|
pub title: String,
|
|
pub artist: String,
|
|
pub src: String,
|
|
pub album: Option<String>,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct WebsiteArticle {
|
|
pub date: NaiveDate,
|
|
pub body: String,
|
|
}
|