add: extended app storage limits

This commit is contained in:
trisua 2025-07-20 20:19:33 -04:00
parent c757ddb77a
commit 9aed5de097
12 changed files with 143 additions and 20 deletions

View file

@ -21,6 +21,35 @@ impl Default for AppQuota {
}
}
/// The storage limit for apps where the owner has a developer pass.
///
/// Free users are always limited to 500 KB.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub enum DeveloperPassStorageQuota {
/// The app is limited to 25 MB.
Tier1,
/// The app is limited to 50 MB.
Tier2,
/// The app is limited to 100 MB.
Tier3,
}
impl Default for DeveloperPassStorageQuota {
fn default() -> Self {
Self::Tier1
}
}
impl DeveloperPassStorageQuota {
pub fn limit(&self) -> usize {
match self {
DeveloperPassStorageQuota::Tier1 => 26214400,
DeveloperPassStorageQuota::Tier2 => 52428800,
DeveloperPassStorageQuota::Tier3 => 104857600,
}
}
}
/// An app is required to request grants on user accounts.
///
/// Users must approve grants through a web portal.
@ -90,6 +119,8 @@ pub struct ThirdPartyApp {
pub api_key: String,
/// The number of bytes the app's app_data rows are using.
pub data_used: usize,
/// The app's storage capacity.
pub storage_capacity: DeveloperPassStorageQuota,
}
impl ThirdPartyApp {
@ -102,12 +133,13 @@ impl ThirdPartyApp {
title,
homepage,
redirect,
quota_status: AppQuota::Limited,
quota_status: AppQuota::default(),
banned: false,
grants: 0,
scopes: Vec::new(),
api_key: String::new(),
data_used: 0,
storage_capacity: DeveloperPassStorageQuota::default(),
}
}
}
@ -132,12 +164,16 @@ impl AppData {
}
/// Get the data limit of a given user.
pub fn user_limit(user: &User) -> usize {
pub fn user_limit(user: &User, app: &ThirdPartyApp) -> usize {
if user
.secondary_permissions
.check(SecondaryPermission::DEVELOPER_PASS)
{
PASS_DATA_LIMIT
if app.storage_capacity != DeveloperPassStorageQuota::Tier1 {
app.storage_capacity.limit()
} else {
PASS_DATA_LIMIT
}
} else {
FREE_DATA_LIMIT
}

View file

@ -1,5 +1,4 @@
use std::collections::HashMap;
use super::{
oauth::AuthGrant,
permissions::{FinePermission, SecondaryPermission},