mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
fix(api): allow hids in uppercase and with dashes; document this
This commit is contained in:
parent
3cefa364b1
commit
bea41ab8a0
2 changed files with 12 additions and 1 deletions
|
|
@ -13,6 +13,15 @@ use crate::auth::AuthState;
|
||||||
use crate::{util::json_err, ApiContext};
|
use crate::{util::json_err, ApiContext};
|
||||||
use pluralkit_models::PKSystem;
|
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<ApiContext>, mut req: Request, next: Next) -> Response {
|
pub async fn params(State(ctx): State<ApiContext>, mut req: Request, next: Next) -> Response {
|
||||||
let pms = match req.extensions().get::<UrlParams>() {
|
let pms = match req.extensions().get::<UrlParams>() {
|
||||||
None => Vec::new(),
|
None => Vec::new(),
|
||||||
|
|
@ -86,7 +95,7 @@ pub async fn params(State(ctx): State<ApiContext>, mut req: Request, next: Next)
|
||||||
Err(_) => sqlx::query_as::<Postgres, PKSystem>(
|
Err(_) => sqlx::query_as::<Postgres, PKSystem>(
|
||||||
"select * from systems where hid = $1",
|
"select * from systems where hid = $1",
|
||||||
)
|
)
|
||||||
.bind(id),
|
.bind(parse_hid(id)),
|
||||||
}
|
}
|
||||||
.fetch_optional(&ctx.db)
|
.fetch_optional(&ctx.db)
|
||||||
.await
|
.await
|
||||||
|
|
|
||||||
|
|
@ -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.
|
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
|
### System model
|
||||||
|
|
||||||
|key|type|notes|
|
|key|type|notes|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue