From 78d046afbd60bda7532f005ac9bb7e4f0805850d Mon Sep 17 00:00:00 2001 From: Gunwant Jain Date: Thu, 8 Jul 2021 18:43:47 +0530 Subject: [PATCH] main: add more routes for pretty pasting cleaned up code and added a route for signifying code language explicitly at `/p/.` Also async-ified the server after upgrading Rocket to 0.5-rc1 Signed-off-by: Gunwant Jain --- Cargo.toml | 8 +++-- src/main.rs | 86 +++++++++++++++++++++++++++----------------- src/pretty_syntax.rs | 43 ++++++++++++++++++++++ 3 files changed, 102 insertions(+), 35 deletions(-) create mode 100644 src/pretty_syntax.rs diff --git a/Cargo.toml b/Cargo.toml index 006b958..264ebb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,11 @@ edition = "2018" [dependencies] rand = "0.8.0" -rocket = "0.4.6" -rocket_contrib = { version = "0.4.6", features = ["tera_templates"] } +rocket = "0.5.0-rc.1" tree_magic = "0.2.3" +syntect = "4.5.0" + +[dependencies.rocket_dyn_templates] +version = "0.1.0-rc.1" +features = ["tera"] diff --git a/src/main.rs b/src/main.rs index a0a74b3..ab193f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,8 @@ -#![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; +use rocket::data::{Data, ToByteUnit}; +use rocket::{form::Form, response::Redirect}; +use rocket_dyn_templates::Template; extern crate tree_magic; @@ -8,32 +10,51 @@ use std::collections::HashMap; use std::env; use std::fs; use std::fs::File; -use std::io::prelude::*; use std::path::Path; -use rocket::request::Form; -use rocket::response::Redirect; -use rocket::Data; -use rocket_contrib::templates::Template; - mod paste_id; +mod pretty; +mod pretty_syntax; use paste_id::PasteId; +use pretty::get_pretty_body; +use pretty_syntax::PasteIdSyntax; + +#[get("/p/", rank = 1)] +async fn pretty_retrieve_ext(id_ext: PasteIdSyntax<'_>) -> Option