From 98290ad23068deb6cd1682b31022f31c28b6cb98 Mon Sep 17 00:00:00 2001 From: imnyang Date: Thu, 12 Mar 2026 18:43:53 +0900 Subject: [PATCH 1/2] raw issue solved --- src/routes.rs | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/routes.rs b/src/routes.rs index 246226f..e7fe40e 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -1,13 +1,21 @@ use crate::config::{AppConfig, normalize_extension}; use content_inspector::ContentType; use rocket::data::{Data, ToByteUnit}; -use rocket::{State, http::Status, response::content::RawHtml}; +use rocket::http::{Accept, MediaType, Status}; +use rocket::response::content::{RawHtml, RawText}; +use rocket::{Responder, State}; 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"); @@ -15,22 +23,28 @@ pub fn index() -> Option> { } #[get("/?")] -pub async fn get_file(id: &str, raw: Option, config: &State) -> Result { +pub async fn get_file( + id: &str, + raw: Option, + accept: Option<&Accept>, + 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 is_mozilla = std::env::var("HTTP_USER_AGENT") - .as_deref() - .unwrap_or("") - .contains("Mozilla"); + let wants_html = accept + .map(|accept| accept.preferred().media_type() == &MediaType::HTML) + .unwrap_or(false); - if raw.unwrap_or(false) || !is_mozilla { - return Ok(content); + if raw.unwrap_or(false) || !wants_html { + return Ok(FileResponse::Text(RawText(content))); } let html: &str = include_str!("assets/editor.html"); - return Ok(html.replace("$%{defaultText}%$", &content)); + return Ok(FileResponse::Html(RawHtml( + html.replace("$%{defaultText}%$", &content), + ))); } } From 667638a9cee04d623175a563bf09b92281907915 Mon Sep 17 00:00:00 2001 From: imnyang Date: Thu, 12 Mar 2026 18:44:16 +0900 Subject: [PATCH 2/2] improve frontend --- config.toml | 2 +- src/assets/editor.html | 280 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 262 insertions(+), 20 deletions(-) diff --git a/config.toml b/config.toml index 8dc4573..054896a 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 1671280..21e9e77 100644 --- a/src/assets/editor.html +++ b/src/assets/editor.html @@ -4,6 +4,7 @@ + paste @@ -54,8 +98,33 @@
    -
  • -
  • +
  • +
  • +
+
    +
  • + + +
  • +
  • + + . + +
@@ -67,63 +136,236 @@