mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2025-09-06 01:10:40 +00:00
add config for max views, expiration and advanced
This commit is contained in:
@@ -1,25 +1,12 @@
|
||||
use actix_web::{get, web, HttpResponse, Responder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use actix_web::web;
|
||||
|
||||
use crate::note;
|
||||
use crate::size::LIMIT;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Status {
|
||||
version: String,
|
||||
max_size: usize,
|
||||
}
|
||||
|
||||
#[get("/status")]
|
||||
async fn status() -> impl Responder {
|
||||
return HttpResponse::Ok().json(Status {
|
||||
version: option_env!("CARGO_PKG_VERSION")
|
||||
.unwrap_or("Unknown")
|
||||
.to_string(),
|
||||
max_size: *LIMIT,
|
||||
});
|
||||
}
|
||||
use crate::status;
|
||||
|
||||
pub fn init(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(web::scope("/api").service(note::service()).service(status));
|
||||
cfg.service(
|
||||
web::scope("/api")
|
||||
.service(note::init())
|
||||
.service(status::init()),
|
||||
);
|
||||
}
|
||||
|
23
backend/src/config.rs
Normal file
23
backend/src/config.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use byte_unit::Byte;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref VERSION: String = option_env!("CARGO_PKG_VERSION")
|
||||
.unwrap_or("Unknown")
|
||||
.to_string();
|
||||
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 static ref MAX_VIEWS: usize = std::env::var("MAX_VIEWS")
|
||||
.unwrap_or("100".to_string())
|
||||
.parse()
|
||||
.unwrap();
|
||||
pub static ref MAX_EXPIRATION: usize = std::env::var("MAX_EXPIRATION")
|
||||
.unwrap_or("360".to_string()) // 6 hours in minutes
|
||||
.parse()
|
||||
.unwrap();
|
||||
pub static ref ALLOW_ADVANCED: bool = std::env::var("ALLOW_ADVANCED")
|
||||
.unwrap_or("true".to_string())
|
||||
.parse()
|
||||
.unwrap();
|
||||
}
|
@@ -6,8 +6,10 @@ extern crate lazy_static;
|
||||
|
||||
mod api;
|
||||
mod client;
|
||||
mod config;
|
||||
mod note;
|
||||
mod size;
|
||||
mod status;
|
||||
mod store;
|
||||
|
||||
#[actix_web::main]
|
||||
|
@@ -110,7 +110,7 @@ struct Status {
|
||||
max_size: usize,
|
||||
}
|
||||
|
||||
pub fn service() -> Scope {
|
||||
pub fn init() -> Scope {
|
||||
web::scope("/notes")
|
||||
.service(one)
|
||||
.service(create)
|
||||
|
5
backend/src/status/mod.rs
Normal file
5
backend/src/status/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
mod model;
|
||||
mod routes;
|
||||
|
||||
pub use model::*;
|
||||
pub use routes::*;
|
10
backend/src/status/model.rs
Normal file
10
backend/src/status/model.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Status {
|
||||
pub version: String,
|
||||
pub max_size: usize,
|
||||
pub max_views: usize,
|
||||
pub max_expiration: usize,
|
||||
pub allow_advanced: bool,
|
||||
}
|
19
backend/src/status/routes.rs
Normal file
19
backend/src/status/routes.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use actix_web::{get, web, HttpResponse, Responder, Scope};
|
||||
|
||||
use crate::config;
|
||||
use crate::status::Status;
|
||||
|
||||
#[get("/")]
|
||||
async fn get_status() -> impl Responder {
|
||||
return HttpResponse::Ok().json(Status {
|
||||
version: config::VERSION.to_string(),
|
||||
max_size: *config::LIMIT,
|
||||
max_views: *config::MAX_VIEWS,
|
||||
max_expiration: *config::MAX_EXPIRATION,
|
||||
allow_advanced: *config::ALLOW_ADVANCED,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn init() -> Scope {
|
||||
web::scope("/status").service(get_status)
|
||||
}
|
Reference in New Issue
Block a user