add: increase image proxy limit for supporters

This commit is contained in:
trisua 2025-06-16 19:50:10 -04:00
parent c55d8bd38b
commit 822aaed0c8
2 changed files with 21 additions and 4 deletions

View file

@ -583,7 +583,9 @@
(li
(text "Create up to 10 stack blocks"))
(li
(text "Add unlimited users to stacks")))
(text "Add unlimited users to stacks"))
(li
(text "Increased proxied image size")))
(a
("href" "{{ config.stripe.payment_link }}?client_reference_id={{ user.id }}")
("class" "button")

View file

@ -1,5 +1,5 @@
use super::auth::images::read_image;
use crate::State;
use crate::{get_user_from_token, State};
use axum::{
body::Body,
extract::Query,
@ -7,10 +7,13 @@ use axum::{
response::IntoResponse,
Extension,
};
use axum_extra::extract::CookieJar;
use pathbufd::PathBufD;
use serde::Deserialize;
use tetratto_core::model::permissions::FinePermission;
pub const MAXIMUM_PROXY_FILE_SIZE: u64 = 4194304; // 4 MiB
pub const MAXIMUM_PROXY_FILE_SIZE: u64 = 4_194_304; // 4 MiB
pub const MAXIMUM_SUPPORTER_PROXY_FILE_SIZE: u64 = 10_485_760; // 4 MiB
#[derive(Deserialize)]
pub struct ProxyQuery {
@ -19,10 +22,22 @@ pub struct ProxyQuery {
/// Proxy an external url
pub async fn proxy_request(
jar: CookieJar,
Query(props): Query<ProxyQuery>,
Extension(data): Extension<State>,
) -> impl IntoResponse {
let data = &(data.read().await);
let user = get_user_from_token!(jar, data.0);
let maximum_size = if let Some(ref ua) = user {
if ua.permissions.check(FinePermission::SUPPORTER) {
MAXIMUM_SUPPORTER_PROXY_FILE_SIZE
} else {
MAXIMUM_PROXY_FILE_SIZE
}
} else {
MAXIMUM_PROXY_FILE_SIZE
};
let http = &data.2;
let data = &data.0.0;
@ -60,7 +75,7 @@ pub async fn proxy_request(
match http.get(image_url).send().await {
Ok(stream) => {
let size = stream.content_length();
if size.unwrap_or_default() > MAXIMUM_PROXY_FILE_SIZE {
if size.unwrap_or_default() > maximum_size {
// return defualt image (content too big)
return (
[("Content-Type", "image/svg+xml")],