add: apps api
This commit is contained in:
parent
2a99d49c8a
commit
ebded00fd3
33 changed files with 698 additions and 31 deletions
60
crates/core/src/model/apps.rs
Normal file
60
crates/core/src/model/apps.rs
Normal file
|
@ -0,0 +1,60 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
pub enum AppQuota {
|
||||
/// The app is limited to 5 grants.
|
||||
Limited,
|
||||
/// The app is allowed to maintain an unlimited number of grants.
|
||||
Unlimited,
|
||||
}
|
||||
|
||||
impl Default for AppQuota {
|
||||
fn default() -> Self {
|
||||
Self::Limited
|
||||
}
|
||||
}
|
||||
|
||||
/// An app is required to request grants on user accounts.
|
||||
///
|
||||
/// Users must approve grants through a web portal.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct ThirdPartyApp {
|
||||
pub id: usize,
|
||||
pub created: usize,
|
||||
/// The ID of the owner of the app.
|
||||
pub owner: usize,
|
||||
/// The name of the app.
|
||||
pub title: String,
|
||||
/// The URL of the app's homepage.
|
||||
pub homepage: String,
|
||||
/// The redirect URL for the app.
|
||||
///
|
||||
/// Upon accepting a grant request, the user will be redirected to this URL
|
||||
/// with a query parameter named `token`, which should be saved by the app
|
||||
/// for future authentication.
|
||||
pub redirect: String,
|
||||
/// The app's quota status, which determines how many grants the app is allowed to maintain.
|
||||
pub quota_status: AppQuota,
|
||||
/// If the app is banned. A banned app cannot use any of its grants.
|
||||
pub banned: bool,
|
||||
/// The number of accepted grants the app maintains.
|
||||
pub grants: usize,
|
||||
}
|
||||
|
||||
impl ThirdPartyApp {
|
||||
/// Create a new [`ThirdPartyApp`].
|
||||
pub fn new(title: String, owner: usize, homepage: String, redirect: String) -> Self {
|
||||
Self {
|
||||
id: Snowflake::new().to_string().parse::<usize>().unwrap(),
|
||||
created: unix_epoch_timestamp() as usize,
|
||||
owner,
|
||||
title,
|
||||
homepage,
|
||||
redirect,
|
||||
quota_status: AppQuota::Limited,
|
||||
banned: false,
|
||||
grants: 0,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue