[code] improve structure (focus: server)

This commit is contained in:
2025-03-02 13:06:18 +01:00
parent bcf9ad68ad
commit adf6f9d757
11 changed files with 393 additions and 368 deletions

View File

@ -1,7 +1,7 @@
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::doc_markdown)]
use std::{collections::HashMap, fmt};
use std::{collections::HashMap, fmt, path::Path};
use bytes::Bytes;
use serde::{Deserialize, Serialize};
@ -93,6 +93,17 @@ impl GameDB {
db
}
pub fn add_thumbnails(&mut self, thumbs_dir: &Path) {
for game in self.games.values_mut() {
let asset = thumbs_dir.join(format!("{}.jpg", game.id));
if let Ok(data) = std::fs::read(&asset) {
game.thumbnail = Some(Bytes::from(data));
} else {
tracing::warn!("Thumbnail missing: {}", game.id);
}
}
}
#[must_use]
pub fn get_game_by_id<S>(&self, id: S) -> Option<&Game>
where