diff --git a/crates/api/src/middleware/params.rs b/crates/api/src/middleware/params.rs index f1219614..ce4850bc 100644 --- a/crates/api/src/middleware/params.rs +++ b/crates/api/src/middleware/params.rs @@ -13,6 +13,15 @@ use crate::auth::AuthState; use crate::{util::json_err, ApiContext}; use pluralkit_models::PKSystem; +// move this somewhere else +fn parse_hid(hid: &str) -> String { + if hid.len() > 7 || hid.len() < 5 { + hid.to_string() + } else { + hid.to_lowercase().replace("-", "") + } +} + pub async fn params(State(ctx): State, mut req: Request, next: Next) -> Response { let pms = match req.extensions().get::() { None => Vec::new(), @@ -86,7 +95,7 @@ pub async fn params(State(ctx): State, mut req: Request, next: Next) Err(_) => sqlx::query_as::( "select * from systems where hid = $1", ) - .bind(id), + .bind(parse_hid(id)), } .fetch_optional(&ctx.db) .await diff --git a/docs/content/api/models.md b/docs/content/api/models.md index 23ecdc3c..558cb622 100644 --- a/docs/content/api/models.md +++ b/docs/content/api/models.md @@ -16,6 +16,8 @@ Privacy objects (`privacy` key in models) contain values "private" or "public". Every PluralKit entity has two IDs: a short (5 or 6 character) ID and a longer UUID. The short ID is unique across the resource (a member can have the same short ID as a system, for example), while the UUID is consistent for the lifetime of the entity and globally unique across the bot. +The PluralKit Discord bot can be configured to display short IDs in uppercase, or (in the case of 6-character IDs) as two parts of 3 characters separated by a dash (for example, `EXA-MPL`). For convenience, IDs are accepted by the API in any format displayable by the bot. + ### System model |key|type|notes|