diff --git a/README.md b/README.md index 17678e8..49fc2d9 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ services: depends_on: - redis environment: - SIZE_LIMIT: 4M + SIZE_LIMIT: 4 MiB ports: - 80:5000 ``` diff --git a/README_zh-CN.md b/README_zh-CN.md index c9f4c7f..e91f001 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -78,7 +78,7 @@ services: depends_on: - redis environment: - SIZE_LIMIT: 4M + SIZE_LIMIT: 4 MiB ports: - 80:5000 ``` diff --git a/backend/src/config.rs b/backend/src/config.rs index 3176709..ff87c78 100644 --- a/backend/src/config.rs +++ b/backend/src/config.rs @@ -9,10 +9,10 @@ lazy_static! { // CONFIG 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())) .unwrap() - .get_bytes() as u32; + .get_bytes() as usize; pub static ref MAX_VIEWS: u32 = std::env::var("MAX_VIEWS") .unwrap_or("100".to_string()) .parse() diff --git a/backend/src/size.rs b/backend/src/size.rs index 3fd3f23..90f20d9 100644 --- a/backend/src/size.rs +++ b/backend/src/size.rs @@ -1,18 +1,11 @@ +use crate::config; use actix_web::web; -use byte_unit::Byte; 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) { - let json = web::JsonConfig::default().limit(*LIMIT); + let json = web::JsonConfig::default().limit(*config::LIMIT); let plain = web::PayloadConfig::default() - .limit(*LIMIT) + .limit(*config::LIMIT) .mimetype(mime::STAR_STAR); cfg.app_data(json).app_data(plain); } diff --git a/backend/src/status/routes.rs b/backend/src/status/routes.rs index d174c2c..bbb8a43 100644 --- a/backend/src/status/routes.rs +++ b/backend/src/status/routes.rs @@ -7,7 +7,7 @@ use crate::status::Status; async fn get_status() -> impl Responder { return HttpResponse::Ok().json(Status { version: config::VERSION.to_string(), - max_size: *config::LIMIT, + max_size: *config::LIMIT as u32, max_views: *config::MAX_VIEWS, max_expiration: *config::MAX_EXPIRATION, allow_advanced: *config::ALLOW_ADVANCED, diff --git a/docker-compose.yml b/docker-compose.yml index a7616b7..1dfdfb9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,6 +14,6 @@ services: depends_on: - redis environment: - SIZE_LIMIT: 128M + SIZE_LIMIT: 128 MiB ports: - 80:5000