clear up limit sizes

This commit is contained in:
cupcakearmy 2022-07-16 14:07:16 +02:00
parent 0829d78481
commit 3e42ae4b10
No known key found for this signature in database
GPG Key ID: 3235314B4D31232F
6 changed files with 9 additions and 16 deletions

View File

@ -82,7 +82,7 @@ services:
depends_on: depends_on:
- redis - redis
environment: environment:
SIZE_LIMIT: 4M SIZE_LIMIT: 4 MiB
ports: ports:
- 80:5000 - 80:5000
``` ```

View File

@ -78,7 +78,7 @@ services:
depends_on: depends_on:
- redis - redis
environment: environment:
SIZE_LIMIT: 4M SIZE_LIMIT: 4 MiB
ports: ports:
- 80:5000 - 80:5000
``` ```

View File

@ -9,10 +9,10 @@ lazy_static! {
// CONFIG // CONFIG
lazy_static! { lazy_static! {
pub static ref LIMIT: u32 = pub static ref LIMIT: usize =
Byte::from_str(std::env::var("SIZE_LIMIT").unwrap_or("1 KiB".to_string())) Byte::from_str(std::env::var("SIZE_LIMIT").unwrap_or("1 KiB".to_string()))
.unwrap() .unwrap()
.get_bytes() as u32; .get_bytes() as usize;
pub static ref MAX_VIEWS: u32 = std::env::var("MAX_VIEWS") pub static ref MAX_VIEWS: u32 = std::env::var("MAX_VIEWS")
.unwrap_or("100".to_string()) .unwrap_or("100".to_string())
.parse() .parse()

View File

@ -1,18 +1,11 @@
use crate::config;
use actix_web::web; use actix_web::web;
use byte_unit::Byte;
use mime; use mime;
lazy_static! {
pub static ref LIMIT: usize =
Byte::from_str(std::env::var("SIZE_LIMIT").unwrap_or("1 KiB".to_string()))
.unwrap()
.get_bytes() as usize;
}
pub fn init(cfg: &mut web::ServiceConfig) { pub fn init(cfg: &mut web::ServiceConfig) {
let json = web::JsonConfig::default().limit(*LIMIT); let json = web::JsonConfig::default().limit(*config::LIMIT);
let plain = web::PayloadConfig::default() let plain = web::PayloadConfig::default()
.limit(*LIMIT) .limit(*config::LIMIT)
.mimetype(mime::STAR_STAR); .mimetype(mime::STAR_STAR);
cfg.app_data(json).app_data(plain); cfg.app_data(json).app_data(plain);
} }

View File

@ -7,7 +7,7 @@ use crate::status::Status;
async fn get_status() -> impl Responder { async fn get_status() -> impl Responder {
return HttpResponse::Ok().json(Status { return HttpResponse::Ok().json(Status {
version: config::VERSION.to_string(), version: config::VERSION.to_string(),
max_size: *config::LIMIT, max_size: *config::LIMIT as u32,
max_views: *config::MAX_VIEWS, max_views: *config::MAX_VIEWS,
max_expiration: *config::MAX_EXPIRATION, max_expiration: *config::MAX_EXPIRATION,
allow_advanced: *config::ALLOW_ADVANCED, allow_advanced: *config::ALLOW_ADVANCED,

View File

@ -14,6 +14,6 @@ services:
depends_on: depends_on:
- redis - redis
environment: environment:
SIZE_LIMIT: 128M SIZE_LIMIT: 128 MiB
ports: ports:
- 80:5000 - 80:5000