add: extended app storage limits
This commit is contained in:
parent
c757ddb77a
commit
9aed5de097
12 changed files with 143 additions and 20 deletions
|
@ -258,6 +258,7 @@ version = "1.0.0"
|
|||
"developer:label.change_homepage" = "Change homepage"
|
||||
"developer:label.change_redirect" = "Change redirect URL"
|
||||
"developer:label.change_quota_status" = "Change quota status"
|
||||
"developer:label.change_storage_capacity" = "Change storage capacity"
|
||||
"developer:label.manage_scopes" = "Manage scopes"
|
||||
"developer:label.scopes" = "Scopes"
|
||||
"developer:label.guides_and_help" = "Guides & help"
|
||||
|
|
|
@ -44,6 +44,28 @@
|
|||
("value" "Unlimited")
|
||||
("selected" "{% if app.quota_status == 'Unlimited' -%}true{% else %}false{%- endif %}")
|
||||
(text "Unlimited")))))
|
||||
(div
|
||||
("class" "card-nest")
|
||||
(div
|
||||
("class" "card small flex items-center gap-2")
|
||||
(icon (text "database-zap"))
|
||||
(b (str (text "developer:label.change_storage_capacity"))))
|
||||
(div
|
||||
("class" "card")
|
||||
(select
|
||||
("onchange" "save_storage_capacity(event)")
|
||||
(option
|
||||
("value" "Tier1")
|
||||
("selected" "{% if app.storage_capacity == 'Tier1' -%}true{% else %}false{%- endif %}")
|
||||
(text "Tier 1 (25 MB)"))
|
||||
(option
|
||||
("value" "Tier2")
|
||||
("selected" "{% if app.storage_capacity == 'Tier2' -%}true{% else %}false{%- endif %}")
|
||||
(text "Tier 2 (50 MB)"))
|
||||
(option
|
||||
("value" "Tier3")
|
||||
("selected" "{% if app.storage_capacity == 'Tier3' -%}true{% else %}false{%- endif %}")
|
||||
(text "Tier 3 (100 MB)")))))
|
||||
(text "{%- endif %}")
|
||||
(div
|
||||
("class" "card-nest")
|
||||
|
@ -232,6 +254,26 @@
|
|||
});
|
||||
};
|
||||
|
||||
globalThis.save_storage_capacity = (event) => {
|
||||
const selected = event.target.selectedOptions[0];
|
||||
fetch(\"/api/v1/apps/{{ app.id }}/storage_capacity\", {
|
||||
method: \"POST\",
|
||||
headers: {
|
||||
\"Content-Type\": \"application/json\",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
storage_capacity: selected.value,
|
||||
}),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger(\"atto::toast\", [
|
||||
res.ok ? \"success\" : \"error\",
|
||||
res.message,
|
||||
]);
|
||||
});
|
||||
};
|
||||
|
||||
globalThis.change_title = async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ pub async fn create_request(
|
|||
|
||||
// check size
|
||||
let new_size = app.data_used + req.value.len();
|
||||
if new_size > AppData::user_limit(&owner) {
|
||||
if new_size > AppData::user_limit(&owner, &app) {
|
||||
return Json(Error::AppHitStorageLimit.into());
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ pub async fn update_value_request(
|
|||
let size_without = app.data_used - app_data.value.len();
|
||||
let new_size = size_without + req.value.len();
|
||||
|
||||
if new_size > AppData::user_limit(&owner) {
|
||||
if new_size > AppData::user_limit(&owner, &app) {
|
||||
return Json(Error::AppHitStorageLimit.into());
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ use tetratto_core::model::{
|
|||
ApiReturn, Error,
|
||||
};
|
||||
use tetratto_shared::{hash::random_id, unix_epoch_timestamp};
|
||||
use super::CreateApp;
|
||||
use super::{CreateApp, UpdateAppStorageCapacity};
|
||||
|
||||
pub async fn create_request(
|
||||
jar: CookieJar,
|
||||
|
@ -138,6 +138,35 @@ pub async fn update_quota_status_request(
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn update_storage_capacity_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(id): Path<usize>,
|
||||
Json(req): Json<UpdateAppStorageCapacity>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
if !user.permissions.check(FinePermission::MANAGE_APPS) {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
|
||||
match data
|
||||
.update_app_storage_capacity(id, req.storage_capacity)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "App updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn update_scopes_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
|
|
|
@ -20,9 +20,9 @@ use axum::{
|
|||
routing::{any, delete, get, post, put},
|
||||
Router,
|
||||
};
|
||||
use serde::{Deserialize};
|
||||
use serde::Deserialize;
|
||||
use tetratto_core::model::{
|
||||
apps::{AppDataSelectMode, AppDataSelectQuery, AppQuota},
|
||||
apps::{AppDataSelectMode, AppDataSelectQuery, AppQuota, DeveloperPassStorageQuota},
|
||||
auth::AchievementName,
|
||||
communities::{
|
||||
CommunityContext, CommunityJoinAccess, CommunityReadAccess, CommunityWriteAccess,
|
||||
|
@ -432,6 +432,10 @@ pub fn routes() -> Router {
|
|||
"/apps/{id}/quota_status",
|
||||
post(apps::update_quota_status_request),
|
||||
)
|
||||
.route(
|
||||
"/apps/{id}/storage_capacity",
|
||||
post(apps::update_storage_capacity_request),
|
||||
)
|
||||
.route("/apps/{id}/scopes", post(apps::update_scopes_request))
|
||||
.route("/apps/{id}/grant", post(apps::grant_request))
|
||||
.route("/apps/{id}/roll", post(apps::roll_api_key_request))
|
||||
|
@ -1031,6 +1035,11 @@ pub struct UpdateAppQuotaStatus {
|
|||
pub quota_status: AppQuota,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateAppStorageCapacity {
|
||||
pub storage_capacity: DeveloperPassStorageQuota,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateAppScopes {
|
||||
pub scopes: Vec<AppScope>,
|
||||
|
|
|
@ -62,7 +62,7 @@ pub async fn app_request(
|
|||
));
|
||||
}
|
||||
|
||||
let data_limit = AppData::user_limit(&user);
|
||||
let data_limit = AppData::user_limit(&user, &app);
|
||||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0.0, lang, &Some(user)).await;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue