add: ability to generate invite codes in bulk add: better mark as nsfw
ui
This commit is contained in:
parent
2a77c61bf2
commit
4843688fcf
13 changed files with 126 additions and 90 deletions
|
@ -832,8 +832,9 @@ pub async fn refresh_grant_request(
|
|||
/// Generate an invite code.
|
||||
///
|
||||
/// Does not support third-party grants.
|
||||
pub async fn generate_invite_code_request(
|
||||
pub async fn generate_invite_codes_request(
|
||||
jar: CookieJar,
|
||||
Path(count): Path<usize>,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
|
@ -846,15 +847,25 @@ pub async fn generate_invite_code_request(
|
|||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
|
||||
match data
|
||||
.create_invite_code(InviteCode::new(user.id), &user)
|
||||
.await
|
||||
{
|
||||
Ok(x) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Code generated".to_string(),
|
||||
payload: Some(x.code),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
if count > 48 {
|
||||
return Json(Error::DataTooLong("count".to_string()).into());
|
||||
}
|
||||
|
||||
let mut out_string = String::new();
|
||||
|
||||
for _ in 0..count {
|
||||
match data
|
||||
.create_invite_code(InviteCode::new(user.id), &user)
|
||||
.await
|
||||
{
|
||||
Ok(x) => out_string += &(x.code + "\n"),
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
|
||||
Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Success".to_string(),
|
||||
payload: Some(out_string),
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue