mirror of
https://github.com/Dangoware/confetti-box.git
synced 2025-04-19 15:22:57 -05:00
Added /info/<mmid>
endpoint
This commit is contained in:
parent
96a6b5cf9d
commit
d4fa87e6fb
4 changed files with 17 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -34,7 +34,7 @@ pub fn server_info(settings: &State<Settings>) -> Json<ServerInfo> {
|
|||
|
||||
/// Get information about a file
|
||||
#[get("/info/<mmid>")]
|
||||
pub async fn file_information(
|
||||
pub async fn file_info(
|
||||
db: &State<Arc<RwLock<Database>>>,
|
||||
mmid: &str,
|
||||
) -> Option<Json<MochiFile>> {
|
||||
|
|
|
@ -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,
|
||||
|
|
11
src/pages.rs
11
src/pages.rs
|
@ -83,6 +83,17 @@ pub fn api_info(settings: &State<Settings>) -> 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/<mmid>"} }
|
||||
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/<mmid>"} }
|
||||
pre { r#"GET mmid=MMID -> Redirect or File"# }
|
||||
|
|
Loading…
Reference in a new issue