diff --git a/config.toml b/config.toml index 054896a..8dc4573 100644 --- a/config.toml +++ b/config.toml @@ -11,5 +11,5 @@ port = 8000 # b, kb, mb, gb, tb # kib, mib, gib, tib max_size = "10MB" -# extension_whitelist = [".docx", ".md", ".json", ".rs"] +extension_whitelist = [".docx", ".md", ".json", ".rs"] block_binary = true diff --git a/src/assets/editor.html b/src/assets/editor.html index 21e9e77..1671280 100644 --- a/src/assets/editor.html +++ b/src/assets/editor.html @@ -4,7 +4,6 @@ - paste @@ -98,33 +54,8 @@
-
@@ -136,236 +67,63 @@ diff --git a/src/routes.rs b/src/routes.rs index e7fe40e..246226f 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -1,21 +1,13 @@ use crate::config::{AppConfig, normalize_extension}; use content_inspector::ContentType; use rocket::data::{Data, ToByteUnit}; -use rocket::http::{Accept, MediaType, Status}; -use rocket::response::content::{RawHtml, RawText}; -use rocket::{Responder, State}; +use rocket::{State, http::Status, response::content::RawHtml}; use std::fs; use std::io::Write; use std::path::Path; use tempfile::NamedTempFile; use tokio::fs as async_fs; -#[derive(Responder)] -pub enum FileResponse { - Html(RawHtml), - Text(RawText), -} - #[get("/")] pub fn index() -> Option> { let raw: &str = include_str!("assets/editor.html"); @@ -23,28 +15,22 @@ pub fn index() -> Option> { } #[get("/?")] -pub async fn get_file( - id: &str, - raw: Option, - accept: Option<&Accept>, - config: &State, -) -> Result { +pub async fn get_file(id: &str, raw: Option, config: &State) -> Result { let file_path = Path::new(&config.upload_dir).join(id); if file_path.exists() { if let Ok(content) = async_fs::read_to_string(file_path).await { - let wants_html = accept - .map(|accept| accept.preferred().media_type() == &MediaType::HTML) - .unwrap_or(false); + let is_mozilla = std::env::var("HTTP_USER_AGENT") + .as_deref() + .unwrap_or("") + .contains("Mozilla"); - if raw.unwrap_or(false) || !wants_html { - return Ok(FileResponse::Text(RawText(content))); + if raw.unwrap_or(false) || !is_mozilla { + return Ok(content); } let html: &str = include_str!("assets/editor.html"); - return Ok(FileResponse::Html(RawHtml( - html.replace("$%{defaultText}%$", &content), - ))); + return Ok(html.replace("$%{defaultText}%$", &content)); } }