diff --git a/Cargo.toml b/Cargo.toml index 30b5827..492a284 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,12 +8,6 @@ strip = true lto = true codegen-units = 1 -# Speed up compilation to make dev bearable -[profile.dev] -debug = 0 -strip = "debuginfo" -codegen-units = 512 - [dependencies] actix-cors = "0.7.1" actix-web = "4.11" @@ -38,7 +32,7 @@ futures-util = "0.3.31" bunny-api-tokio = "0.3.0" bindet = "0.3.2" deadpool = "0.12" -diesel = { version = "2.2", features = ["uuid", "chrono"], default-features = false } +diesel = { version = "2.2", features = ["uuid", "chrono"] } diesel-async = { version = "0.5", features = ["deadpool", "postgres", "async-connection-wrapper"] } diesel_migrations = { version = "2.2.0", features = ["postgres"] } thiserror = "2.0.12" diff --git a/migrations/2025-06-01-143713_add_about_to_users/down.sql b/migrations/2025-06-01-143713_add_about_to_users/down.sql deleted file mode 100644 index de48d07..0000000 --- a/migrations/2025-06-01-143713_add_about_to_users/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -ALTER TABLE users DROP COLUMN about; \ No newline at end of file diff --git a/migrations/2025-06-01-143713_add_about_to_users/up.sql b/migrations/2025-06-01-143713_add_about_to_users/up.sql deleted file mode 100644 index 54b5449..0000000 --- a/migrations/2025-06-01-143713_add_about_to_users/up.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Your SQL goes here -ALTER TABLE users ADD COLUMN about VARCHAR(200) DEFAULT NULL; diff --git a/src/api/v1/channels/uuid/mod.rs b/src/api/v1/channels/uuid/mod.rs index 1874dfc..f429159 100644 --- a/src/api/v1/channels/uuid/mod.rs +++ b/src/api/v1/channels/uuid/mod.rs @@ -1,5 +1,3 @@ -//! `/api/v1/channels/{uuid}` Channel specific endpoints - pub mod messages; pub mod socket; @@ -10,9 +8,8 @@ use crate::{ structs::{Channel, Member}, utils::{get_auth_header, global_checks}, }; -use actix_web::{delete, get, patch, web, HttpRequest, HttpResponse}; +use actix_web::{HttpRequest, HttpResponse, delete, get, web}; use uuid::Uuid; -use serde::Deserialize; #[get("/{uuid}")] pub async fn get( @@ -65,80 +62,3 @@ pub async fn delete( Ok(HttpResponse::Ok().finish()) } - -#[derive(Deserialize)] -struct NewInfo { - name: Option, - description: Option, - is_above: Option, -} - -/// `PATCH /api/v1/channels/{uuid}` Returns user with the given UUID -/// -/// requires auth: yes -/// -/// requires relation: yes -/// -/// ### Request Example -/// All fields are optional and can be nulled/dropped if only changing 1 value -/// ``` -/// json!({ -/// "name": "gaming-chat", -/// "description": "Gaming related topics.", -/// "is_above": "398f6d7b-752c-4348-9771-fe6024adbfb1" -/// }); -/// ``` -/// -/// ### Response Example -/// ``` -/// json!({ -/// uuid: "cdcac171-5add-4f88-9559-3a247c8bba2c", -/// guild_uuid: "383d2afa-082f-4dd3-9050-ca6ed91487b6", -/// name: "gaming-chat", -/// description: "Gaming related topics.", -/// is_above: "398f6d7b-752c-4348-9771-fe6024adbfb1", -/// permissions: { -/// role_uuid: "79cc0806-0f37-4a06-a468-6639c4311a2d", -/// permissions: 0 -/// } -/// }); -/// ``` -/// NOTE: UUIDs in this response are made using `uuidgen`, UUIDs made by the actual backend will be UUIDv7 and have extractable timestamps -#[patch("/{uuid}")] -pub async fn patch( - req: HttpRequest, - path: web::Path<(Uuid,)>, - new_info: web::Json, - data: web::Data, -) -> Result { - let headers = req.headers(); - - let auth_header = get_auth_header(headers)?; - - let channel_uuid = path.into_inner().0; - - let mut conn = data.pool.get().await?; - - let uuid = check_access_token(auth_header, &mut conn).await?; - - global_checks(&data, uuid).await?; - - let mut channel = Channel::fetch_one(&data, channel_uuid).await?; - - Member::check_membership(&mut conn, uuid, channel.guild_uuid).await?; - - if let Some(new_name) = &new_info.name { - channel.set_name(&data, new_name.to_string()).await?; - } - - if let Some(new_description) = &new_info.description { - channel.set_description(&data, new_description.to_string()).await?; - } - - if let Some(new_is_above) = &new_info.is_above { - channel.set_description(&data, new_is_above.to_string()).await?; - } - - Ok(HttpResponse::Ok().json(channel)) -} - diff --git a/src/api/v1/me/mod.rs b/src/api/v1/me/mod.rs index ac35140..fc9e61b 100644 --- a/src/api/v1/me/mod.rs +++ b/src/api/v1/me/mod.rs @@ -41,7 +41,6 @@ struct NewInfo { //password: Option, will probably be handled through a reset password link email: Option, pronouns: Option, - about: Option, } #[derive(Debug, MultipartForm)] @@ -103,9 +102,5 @@ pub async fn update( me.set_pronouns(&data, pronouns.clone()).await?; } - if let Some(about) = &form.json.about { - me.set_about(&data, about.clone()).await?; - } - Ok(HttpResponse::Ok().finish()) } diff --git a/src/schema.rs b/src/schema.rs index 09ea7a3..3be885a 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -146,8 +146,6 @@ diesel::table! { avatar -> Nullable, #[max_length = 32] pronouns -> Nullable, - #[max_length = 200] - about -> Nullable, } } diff --git a/src/structs.rs b/src/structs.rs index b68aaf5..5e19dad 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -24,9 +24,13 @@ use url::Url; use uuid::Uuid; use crate::{ - error::Error, schema::*, utils::{ - generate_refresh_token, global_checks, image_check, order_by_is_above, user_uuid_from_identifier, CHANNEL_REGEX, EMAIL_REGEX, PASSWORD_REGEX, USERNAME_REGEX - }, Conn, Data + Conn, Data, + error::Error, + schema::*, + utils::{ + EMAIL_REGEX, PASSWORD_REGEX, USERNAME_REGEX, generate_refresh_token, global_checks, + image_check, order_by_is_above, user_uuid_from_identifier, + }, }; pub trait HasUuid { @@ -227,10 +231,6 @@ impl Channel { name: String, description: Option, ) -> Result { - if !CHANNEL_REGEX.is_match(&name) { - return Err(Error::BadRequest("Channel name is invalid".to_string())) - } - let mut conn = data.pool.get().await?; let channel_uuid = Uuid::now_v7(); @@ -353,93 +353,6 @@ impl Channel { message.build(data).await } - - pub async fn set_name(&mut self, data: &Data, new_name: String) -> Result<(), Error> { - if !CHANNEL_REGEX.is_match(&new_name) { - return Err(Error::BadRequest("Channel name is invalid".to_string())) - } - - let mut conn = data.pool.get().await?; - - use channels::dsl; - update(channels::table) - .filter(dsl::uuid.eq(self.uuid)) - .set(dsl::name.eq(&new_name)) - .execute(&mut conn) - .await?; - - self.name = new_name; - - Ok(()) - } - - pub async fn set_description(&mut self, data: &Data, new_description: String) -> Result<(), Error> { - let mut conn = data.pool.get().await?; - - use channels::dsl; - update(channels::table) - .filter(dsl::uuid.eq(self.uuid)) - .set(dsl::description.eq(&new_description)) - .execute(&mut conn) - .await?; - - self.description = Some(new_description); - - Ok(()) - } - - pub async fn move_channel(&mut self, data: &Data, new_is_above: Uuid) -> Result<(), Error> { - let mut conn = data.pool.get().await?; - - use channels::dsl; - let old_above_uuid: Option = match dsl::channels - .filter(dsl::is_above.eq(self.uuid)) - .select(dsl::uuid) - .get_result(&mut conn) - .await - { - Ok(r) => Ok(Some(r)), - Err(e) if e == diesel::result::Error::NotFound => Ok(None), - Err(e) => Err(e), - }?; - - if let Some(uuid) = old_above_uuid { - update(channels::table) - .filter(dsl::uuid.eq(uuid)) - .set(dsl::is_above.eq(None::)) - .execute(&mut conn) - .await?; - } - - match update(channels::table) - .filter(dsl::is_above.eq(new_is_above)) - .set(dsl::is_above.eq(self.uuid)) - .execute(&mut conn) - .await - { - Ok(r) => Ok(r), - Err(e) if e == diesel::result::Error::NotFound => Ok(0), - Err(e) => Err(e), - }?; - - update(channels::table) - .filter(dsl::uuid.eq(self.uuid)) - .set(dsl::is_above.eq(new_is_above)) - .execute(&mut conn) - .await?; - - if let Some(uuid) = old_above_uuid { - update(channels::table) - .filter(dsl::uuid.eq(uuid)) - .set(dsl::is_above.eq(self.is_above)) - .execute(&mut conn) - .await?; - } - - self.is_above = Some(new_is_above); - - Ok(()) - } } #[derive(Clone, Copy)] @@ -953,7 +866,6 @@ pub struct User { display_name: Option, avatar: Option, pronouns: Option, - about: Option, } impl User { @@ -1005,7 +917,6 @@ pub struct Me { display_name: Option, avatar: Option, pronouns: Option, - about: Option, email: String, pub email_verified: bool, } @@ -1200,25 +1111,6 @@ impl Me { Ok(()) } - - pub async fn set_about(&mut self, data: &Data, new_about: String) -> Result<(), Error> { - let mut conn = data.pool.get().await?; - - use users::dsl; - update(users::table) - .filter(dsl::uuid.eq(self.uuid)) - .set(( - dsl::about.eq(new_about.as_str()), - )) - .execute(&mut conn) - .await?; - - if data.get_cache_key(self.uuid.to_string()).await.is_ok() { - data.del_cache_key(self.uuid.to_string()).await? - } - - Ok(()) - } } #[derive(Deserialize)] diff --git a/src/utils.rs b/src/utils.rs index 3bf7332..c9f3cb2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -30,9 +30,6 @@ pub static EMAIL_REGEX: LazyLock = LazyLock::new(|| { pub static USERNAME_REGEX: LazyLock = LazyLock::new(|| Regex::new(r"^[a-z0-9_.-]+$").unwrap()); -pub static CHANNEL_REGEX: LazyLock = - LazyLock::new(|| Regex::new(r"^[a-z0-9_.-]+$").unwrap()); - // Password is expected to be hashed using SHA3-384 pub static PASSWORD_REGEX: LazyLock = LazyLock::new(|| Regex::new(r"[0-9a-f]{96}").unwrap());