add: increase image proxy limit for supporters
This commit is contained in:
parent
c55d8bd38b
commit
822aaed0c8
2 changed files with 21 additions and 4 deletions
|
@ -583,7 +583,9 @@
|
||||||
(li
|
(li
|
||||||
(text "Create up to 10 stack blocks"))
|
(text "Create up to 10 stack blocks"))
|
||||||
(li
|
(li
|
||||||
(text "Add unlimited users to stacks")))
|
(text "Add unlimited users to stacks"))
|
||||||
|
(li
|
||||||
|
(text "Increased proxied image size")))
|
||||||
(a
|
(a
|
||||||
("href" "{{ config.stripe.payment_link }}?client_reference_id={{ user.id }}")
|
("href" "{{ config.stripe.payment_link }}?client_reference_id={{ user.id }}")
|
||||||
("class" "button")
|
("class" "button")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use super::auth::images::read_image;
|
use super::auth::images::read_image;
|
||||||
use crate::State;
|
use crate::{get_user_from_token, State};
|
||||||
use axum::{
|
use axum::{
|
||||||
body::Body,
|
body::Body,
|
||||||
extract::Query,
|
extract::Query,
|
||||||
|
@ -7,10 +7,13 @@ use axum::{
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
Extension,
|
Extension,
|
||||||
};
|
};
|
||||||
|
use axum_extra::extract::CookieJar;
|
||||||
use pathbufd::PathBufD;
|
use pathbufd::PathBufD;
|
||||||
use serde::Deserialize;
|
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)]
|
#[derive(Deserialize)]
|
||||||
pub struct ProxyQuery {
|
pub struct ProxyQuery {
|
||||||
|
@ -19,10 +22,22 @@ pub struct ProxyQuery {
|
||||||
|
|
||||||
/// Proxy an external url
|
/// Proxy an external url
|
||||||
pub async fn proxy_request(
|
pub async fn proxy_request(
|
||||||
|
jar: CookieJar,
|
||||||
Query(props): Query<ProxyQuery>,
|
Query(props): Query<ProxyQuery>,
|
||||||
Extension(data): Extension<State>,
|
Extension(data): Extension<State>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let data = &(data.read().await);
|
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 http = &data.2;
|
||||||
let data = &data.0.0;
|
let data = &data.0.0;
|
||||||
|
|
||||||
|
@ -60,7 +75,7 @@ pub async fn proxy_request(
|
||||||
match http.get(image_url).send().await {
|
match http.get(image_url).send().await {
|
||||||
Ok(stream) => {
|
Ok(stream) => {
|
||||||
let size = stream.content_length();
|
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 defualt image (content too big)
|
||||||
return (
|
return (
|
||||||
[("Content-Type", "image/svg+xml")],
|
[("Content-Type", "image/svg+xml")],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue