use crate::{require_auth, RouterContext};
use pylon_http::HttpMethod;
pub(crate) fn handle(
ctx: &RouterContext,
method: HttpMethod,
url: &str,
body: &str,
_auth_token: Option<&str>,
) -> Option<(u16, String)> {
if url == "/api/files/upload" && method == HttpMethod::Post {
let (s, b) = ctx.files.upload(body);
return Some((s, b));
}
if let Some(file_id) = url.strip_prefix("/api/files/") {
let file_id = file_id.split('?').next().unwrap_or(file_id);
if method == HttpMethod::Get {
if let Some(err) = require_auth(ctx) {
return Some(err);
}
let (s, b) = ctx.files.get_file(file_id);
return Some((s, b));
}
}
None
}