Args: implement upload arg

Signed-off-by: Gunwant Jain <mail@wantguns.dev>
This commit is contained in:
Gunwant Jain
2022-01-18 15:48:21 +05:30
parent 6961ed59b4
commit ce001c6a79
6 changed files with 27 additions and 20 deletions

View File

@@ -3,22 +3,22 @@ use rocket_dyn_templates::Template;
use std::collections::HashMap;
use std::path::Path;
use crate::get_upload_dir;
use crate::models::paste_id::PasteId;
use crate::models::pretty::get_pretty_body;
#[get("/p/<id>", rank = 2)]
pub async fn pretty_retrieve(id: PasteId<'_>) -> Option<Template> {
let filename = format!("upload/{id}", id = id);
let filepath = Path::new(&filename);
let filepath = Path::new(&get_upload_dir()).join(format!("{id}", id = id));
let contents = get_pretty_body(&filename, &String::from("txt"));
let contents = get_pretty_body(&filepath, &String::from("txt"));
let mut map = HashMap::new();
map.insert("title", id.to_string());
map.insert("body", contents);
let rendered = Template::render("pretty", &map);
match tree_magic::match_filepath("text/plain", filepath) {
match tree_magic::match_filepath("text/plain", &filepath) {
true => Some(rendered),
false => None,
}