diff --git a/src/database.rs b/src/database.rs index 1486e3b..46991d5 100644 --- a/src/database.rs +++ b/src/database.rs @@ -11,6 +11,7 @@ use rocket::{ serde::{Deserialize, Serialize}, tokio::{select, sync::mpsc::Receiver, time}, }; +use serde_with::{serde_as, DisplayFromStr}; const BINCODE_CFG: Configuration = bincode::config::standard(); @@ -150,6 +151,7 @@ impl Database { } /// An entry in the database storing metadata about a file +#[serde_as] #[derive(Debug, Clone, Decode, Encode, Deserialize, Serialize)] pub struct MochiFile { /// A unique identifier describing this file @@ -163,6 +165,7 @@ pub struct MochiFile { /// The Blake3 hash of the file #[bincode(with_serde)] + #[serde_as(as = "DisplayFromStr")] hash: Hash, /// The datetime when the file was uploaded diff --git a/src/endpoints.rs b/src/endpoints.rs index d5bb222..648f399 100644 --- a/src/endpoints.rs +++ b/src/endpoints.rs @@ -34,7 +34,7 @@ pub fn server_info(settings: &State) -> Json { /// Get information about a file #[get("/info/")] -pub async fn file_information( +pub async fn file_info( db: &State>>, mmid: &str, ) -> Option> { diff --git a/src/main.rs b/src/main.rs index 2b73380..4cffe65 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use std::{ use chrono::{DateTime, TimeDelta, Utc}; use database::{clean_loop, Database, Mmid, MochiFile}; -use endpoints::{lookup_mmid, lookup_mmid_name, lookup_mmid_noredir, server_info}; +use endpoints::{file_info, lookup_mmid, lookup_mmid_name, lookup_mmid_noredir, server_info}; use log::info; use maud::{html, Markup, PreEscaped}; use pages::{api_info, footer, head}; @@ -240,6 +240,7 @@ async fn main() { form_handler_js, stylesheet, server_info, + file_info, favicon, lookup_mmid, lookup_mmid_noredir, diff --git a/src/pages.rs b/src/pages.rs index 8b37f8d..8732ad6 100644 --- a/src/pages.rs +++ b/src/pages.rs @@ -83,6 +83,17 @@ pub fn api_info(settings: &State) -> Markup { "{\n\t\"max_filesize\": 5000000000,\n\t\"max_duration\": 259200,\n\t\"default_duration\": 21600,\n\t\"allowed_durations\": [\n\t\t3600,\n\t\t21600,\n\t\t86400,\n\t\t172800\n\t]\n}" } + hr; + h2 { code {"/info/"} } + pre { r#"GET -> JSON"# } + p { + "Returns information about a file by its MMID." + } + p {"Example response:"} + pre { + "{\n\t\"mmid\": \"xNLF6ogx\",\n\t\"name\": \"1600-1200.jpg\",\n\t\"mime_type\": \"image/png\",\n\t\"hash\": \"2e8e0a493ef99dfd950e870e319213d33573f64ba32b5a5399dd6c79c7d5cf00\",\n\t\"upload_datetime\": \"2024-10-29T22:09:48.648562311Z\",\n\t\"expiry_datetime\": \"2024-10-30T04:09:48.648562311Z\"\n}" + } + hr; h2 { code {"/f/"} } pre { r#"GET mmid=MMID -> Redirect or File"# }