Opting for string keys in json db

This commit is contained in:
shockrah 2025-08-15 20:24:09 -07:00
parent 61b3a5fe80
commit 150d34c38e
2 changed files with 5 additions and 5 deletions

View File

@ -8,23 +8,23 @@ use crate::CONFIG;
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
pub struct Row { pub struct Row {
pub id: i64,
pub file: String, pub file: String,
pub thumbnail: String pub thumbnail: String
} }
type Data = HashMap<String, Row>;
pub fn get_video(id: i64) -> Option<Row> {
pub fn get_video(id: String) -> Option<Row> {
// Used to fetch video information from the db for client's to request // Used to fetch video information from the db for client's to request
// video and thumbnail files from us // video and thumbnail files from us
let db_file = fs::read_to_string(CONFIG.db_file) let db_file = fs::read_to_string(CONFIG.db_file)
.expect("Unable to read DB_FILE"); .expect("Unable to read DB_FILE");
let db_data: HashMap<i64, Row> = json::from_str(&db_file) let db_data: Data = json::from_str(&db_file)
.expect("Unable to parse DB_FILE content"); .expect("Unable to parse DB_FILE content");
match db_data.get(&id) { match db_data.get(&id) {
Some(video) => Some(Row { Some(video) => Some(Row {
id,
file: video.file.clone(), file: video.file.clone(),
thumbnail: video.thumbnail.clone() thumbnail: video.thumbnail.clone()
}), }),

View File

@ -5,7 +5,7 @@ use rocket_dyn_templates::Template;
use rocket_dyn_templates::context; use rocket_dyn_templates::context;
#[get("/<video_id>")] #[get("/<video_id>")]
pub fn index(video_id: i64) -> Template { pub fn index(video_id: String) -> Template {
// Read the db file we have to get the ID // Read the db file we have to get the ID
// Now we can fetch the row from the DB content // Now we can fetch the row from the DB content
match db::get_video(video_id) { match db::get_video(video_id) {