diff --git a/Cargo.lock b/Cargo.lock index 58073d52..cea7e8ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1703,12 +1703,6 @@ dependencies = [ "ahash 0.7.6", ] -[[package]] -name = "heck" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" - [[package]] name = "hermit-abi" version = "0.1.19" @@ -3265,7 +3259,6 @@ dependencies = [ "chrono", "flume", "futures 0.3.21", - "heck", "hex", "once_cell", "openssl", diff --git a/plume-common/Cargo.toml b/plume-common/Cargo.toml index 52dbefdd..2e12a013 100644 --- a/plume-common/Cargo.toml +++ b/plume-common/Cargo.toml @@ -7,7 +7,6 @@ edition = "2018" [dependencies] array_tool = "1.0" base64 = "0.13" -heck = "0.4.0" hex = "0.4" openssl = "0.10.40" rocket = "0.4.6" diff --git a/plume-common/src/utils.rs b/plume-common/src/utils.rs index 17912a02..b4c3dce5 100644 --- a/plume-common/src/utils.rs +++ b/plume-common/src/utils.rs @@ -1,4 +1,3 @@ -use heck::ToUpperCamelCase; use openssl::rand::rand_bytes; use pulldown_cmark::{html, CodeBlockKind, CowStr, Event, LinkType, Options, Parser, Tag}; use regex_syntax::is_word_character; @@ -16,14 +15,6 @@ pub fn random_hex() -> String { .fold(String::new(), |res, byte| format!("{}{:x}", res, byte)) } -/// Remove non alphanumeric characters and CamelCase a string -pub fn make_actor_id(name: &str) -> String { - name.to_upper_camel_case() - .chars() - .filter(|c| c.is_alphanumeric()) - .collect() -} - /** * Percent-encode characters which are not allowed in IRI path segments. * diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index ac20ee86..fb20be48 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -95,6 +95,10 @@ impl Blog { find_by!(blogs, find_by_ap_url, ap_url as &str); find_by!(blogs, find_by_name, actor_id as &str, instance_id as i32); + pub fn slug(title: &str) -> &str { + title + } + pub fn get_instance(&self, conn: &Connection) -> Result { Instance::get(conn, self.instance_id) } diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index 7359779a..b8f28959 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -79,7 +79,7 @@ pub struct NewBlogForm { } fn valid_slug(title: &str) -> Result<(), ValidationError> { - let slug = utils::make_actor_id(title); + let slug = Blog::slug(title); if slug.is_empty() { Err(ValidationError::new("empty_slug")) } else { @@ -93,7 +93,7 @@ pub fn create( conn: DbConn, rockets: PlumeRocket, ) -> RespondOrRedirect { - let slug = utils::make_actor_id(&form.title); + let slug = Blog::slug(&form.title); let intl = &rockets.intl.catalog; let user = rockets.user.clone().unwrap(); @@ -101,7 +101,7 @@ pub fn create( Ok(_) => ValidationErrors::new(), Err(e) => e, }; - if Blog::find_by_fqn(&conn, &slug).is_ok() { + if Blog::find_by_fqn(&conn, slug).is_ok() { errors.add( "title", ValidationError { @@ -122,7 +122,7 @@ pub fn create( let blog = Blog::insert( &conn, NewBlog::new_local( - slug.clone(), + slug.into(), form.title.to_string(), String::from(""), Instance::get_local() @@ -379,6 +379,7 @@ pub fn atom_feed(name: String, conn: DbConn) -> Option> { #[cfg(test)] mod tests { + use super::valid_slug; use crate::init_rocket; use diesel::Connection; use plume_common::utils::random_hex; @@ -524,4 +525,10 @@ mod tests { .finish(), ); } + + #[test] + fn test_valid_slug() { + assert!(valid_slug("Blog Title").is_ok()); + assert!(valid_slug("ブログ タイトル").is_ok()); + } }