From 4faa8e94cdbfa9095313ef52b4d2e6fdf078a94d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sn=C3=ADda=C5=88ov=C3=BD=20Mistr?= Date: Mon, 18 Dec 2023 23:48:05 +0100 Subject: [PATCH] =?UTF-8?q?Bug=20fix=20+=20lep=C5=A1=C3=AD=20n=C3=A1hledy?= =?UTF-8?q?=20gif=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 43 +++++++++---------------------------------- Cargo.toml | 2 +- src/error.rs | 4 ++-- src/files.rs | 7 ++++--- src/filters.rs | 2 +- src/markup.rs | 25 ++++++++++++------------- static/style.css | 1 + 7 files changed, 30 insertions(+), 54 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb475c3..ed9bb2f 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -436,21 +436,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bit-set" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" -dependencies = [ - "bit-vec", -] - -[[package]] -name = "bit-vec" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" - [[package]] name = "bit_field" version = "0.10.2" @@ -1078,16 +1063,6 @@ dependencies = [ "hashbrown 0.13.2", ] -[[package]] -name = "fancy-regex" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7493d4c459da9f84325ad297371a6b2b8a162800873a22e3b6b6512e61d18c05" -dependencies = [ - "bit-set", - "regex", -] - [[package]] name = "fastrand" version = "2.0.0" @@ -1728,9 +1703,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "memoffset" @@ -1815,7 +1790,6 @@ dependencies = [ "encoding", "enumflags2", "env_logger", - "fancy-regex", "fs_extra", "glob", "html-minifier", @@ -1828,6 +1802,7 @@ dependencies = [ "pwhash", "rand", "redis", + "regex", "serde", "serde_json", "serde_qs", @@ -2221,9 +2196,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.4" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", @@ -2233,9 +2208,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.7" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", @@ -2244,9 +2219,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.7.5" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "rgb" diff --git a/Cargo.toml b/Cargo.toml index 71a4ff4..53294c4 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ dotenv = "0.15.0" enumflags2 = "0.7.7" encoding = "0.2.33" env_logger = "0.10.0" -fancy-regex = "0.12.0" glob = "0.3.1" image = "0.24.7" ipnetwork = "0.20.0" @@ -26,6 +25,7 @@ num-traits = "0.2.16" pwhash = "1.0.0" rand = "0.8.5" redis = { version = "0.24.0", features = ["aio", "json", "tokio-comp"] } +regex = "1.10.2" serde = "1.0.166" serde_json = "1.0.100" serde_qs = "0.12.0" diff --git a/src/error.rs b/src/error.rs index da3b21f..ff743b6 100755 --- a/src/error.rs +++ b/src/error.rs @@ -116,8 +116,8 @@ impl From for NekrochanError { } } -impl From for NekrochanError { - fn from(e: fancy_regex::Error) -> Self { +impl From for NekrochanError { + fn from(e: regex::Error) -> Self { error!("Internal server error: {e:#?}"); Self::InternalError diff --git a/src/files.rs b/src/files.rs index 99633ab..d033acb 100755 --- a/src/files.rs +++ b/src/files.rs @@ -91,7 +91,7 @@ impl File { process_image(cfg, original_name.clone(), new_name.clone(), thumb_name).await? }; - rename(format!("/tmp/{new_name}"), format!("uploads/{new_name}")).await?; + rename(format!("/tmp/{new_name}"), format!("./uploads/{new_name}")).await?; let file = File { original_name, @@ -188,6 +188,7 @@ async fn process_image( let output = spawn_blocking(move || { Command::new("convert") .arg(&format!("/tmp/{new_name}")) + .arg("-coalesce") .arg("-thumbnail") .arg(&format!("{thumb_size}x{thumb_size}>")) .arg(&format!("./uploads/thumb/{thumb_name}")) @@ -335,7 +336,7 @@ pub async fn cleanup_files(ctx: &Ctx) -> Result<(), Error> { } } - for file in glob("uploads/*.*")? { + for file in glob("./uploads/*.*")? { let file = file?; let file_name = file.file_name(); @@ -348,7 +349,7 @@ pub async fn cleanup_files(ctx: &Ctx) -> Result<(), Error> { } } - for file in glob("uploads/thumb/*.*")? { + for file in glob("./uploads/thumb/*.*")? { let file = file?; let file_name = file.file_name(); diff --git a/src/filters.rs b/src/filters.rs index 56f06eb..e56bb2d 100644 --- a/src/filters.rs +++ b/src/filters.rs @@ -1,5 +1,5 @@ use chrono::{DateTime, Locale, Utc}; -use fancy_regex::{Captures, Regex}; +use regex::{Captures, Regex}; use lazy_static::lazy_static; use std::{collections::HashSet, fmt::Display}; diff --git a/src/markup.rs b/src/markup.rs index def81f0..e485568 100644 --- a/src/markup.rs +++ b/src/markup.rs @@ -1,5 +1,5 @@ -use fancy_regex::{Captures, Regex}; use lazy_static::lazy_static; +use regex::{Captures, Regex}; use sqlx::query_as; use std::collections::HashMap; @@ -15,15 +15,13 @@ lazy_static! { pub static ref NAME_REGEX: Regex = Regex::new(r"^([^#].*?)?(?:(##([^ ].*?)|#([^#].*?)))?(##( .*?)?)?$").unwrap(); pub static ref QUOTE_REGEX: Regex = Regex::new(r">>(\d+)").unwrap(); - pub static ref GREENTEXT_REGEX: Regex = - Regex::new(r"(?m)^>((?!>\d+|>>/\w+(/\d*)?|>>#/).*)") - .unwrap(); - pub static ref ORANGETEXT_REGEX: Regex = Regex::new(r"(?m)^<(.+)").unwrap(); - pub static ref REDTEXT_REGEX: Regex = Regex::new(r"(?m)==(.+?)==").unwrap(); - pub static ref BLUETEXT_REGEX: Regex = Regex::new(r"(?m)--(.+?)--").unwrap(); - pub static ref GLOWTEXT_REGEX: Regex = Regex::new(r"(?m)\%\%(.+?)\%\%").unwrap(); - pub static ref UH_OH_TEXT_REGEX: Regex = Regex::new(r"(?m)\(\(\((.+?)\)\)\)").unwrap(); - pub static ref SPOILER_REGEX: Regex = Regex::new(r"(?m)\|\|([\s\S]+?)\|\|").unwrap(); + pub static ref GREENTEXT_REGEX: Regex = Regex::new(r"(?mR)^>(.*)$").unwrap(); + pub static ref ORANGETEXT_REGEX: Regex = Regex::new(r"(?mR)^<(.*)$").unwrap(); + pub static ref REDTEXT_REGEX: Regex = Regex::new(r"==(.+?)==").unwrap(); + pub static ref BLUETEXT_REGEX: Regex = Regex::new(r"--(.+?)--").unwrap(); + pub static ref GLOWTEXT_REGEX: Regex = Regex::new(r"\%\%(.+?)\%\%").unwrap(); + pub static ref UH_OH_TEXT_REGEX: Regex = Regex::new(r"\(\(\((.+?)\)\)\)").unwrap(); + pub static ref SPOILER_REGEX: Regex = Regex::new(r"\|\|([\s\S]+?)\|\|").unwrap(); pub static ref URL_REGEX: Regex = Regex::new(r"https?\://[^\s<>\[\]{}|\\^]+").unwrap(); } @@ -34,7 +32,7 @@ pub fn parse_name( anon_name: &str, name: &str, ) -> Result<(String, Option, Option), NekrochanError> { - let Some(captures) = NAME_REGEX.captures(name)? else { + let Some(captures) = NAME_REGEX.captures(name) else { return Ok((anon_name.to_owned(), None, None)); }; @@ -112,7 +110,8 @@ pub async fn markup( op: Option, text: &str, ) -> Result { - let text = escape_html(text); + let text = escape_html(&text); + let quoted_posts = get_quoted_posts(ctx, board, &text).await?; let text = QUOTE_REGEX.replace_all(&text, |captures: &Captures| { @@ -182,7 +181,7 @@ async fn get_quoted_posts( let mut quoted_ids: Vec = Vec::new(); for quote in QUOTE_REGEX.captures_iter(text) { - let id_raw = "e.unwrap()[1]; + let id_raw = "e[1]; let Ok(id) = id_raw.parse() else { continue }; quoted_ids.push(id); diff --git a/static/style.css b/static/style.css index 45e8d98..d451d26 100755 --- a/static/style.css +++ b/static/style.css @@ -221,6 +221,7 @@ summary { .banner { display: block; + width: 100%; max-width: 300px; margin: 8px auto; border: 1px solid var(--box-border);