From 622b156eed177f4ccc6c54cc3021d2af18bf09cf Mon Sep 17 00:00:00 2001 From: Sergio <77530549+sergi0g@users.noreply.github.com> Date: Sat, 7 Dec 2024 17:08:34 +0200 Subject: [PATCH] Add agent mode, fix config version bug --- cup.schema.json | 4 ++++ src/config.rs | 4 +++- src/server.rs | 12 ++++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/cup.schema.json b/cup.schema.json index 237a2ec..ca64eb1 100644 --- a/cup.schema.json +++ b/cup.schema.json @@ -10,6 +10,10 @@ "minimum": 3, "maximum": 3 }, + "agent": { + "type": "boolean", + "description": "Whether or not to enable agent mode. When agent mode is enabled, the server only exposes the API and the web interface is unavailable." + }, "registries": { "type": "object", "description": "Configuration options for specific registries", diff --git a/src/config.rs b/src/config.rs index 6e7df52..6c8e6ab 100644 --- a/src/config.rs +++ b/src/config.rs @@ -39,6 +39,7 @@ pub struct ImageConfig { #[serde(default)] pub struct Config { version: u8, + pub agent: bool, pub registries: FxHashMap, pub images: ImageConfig, pub theme: Theme, @@ -51,6 +52,7 @@ impl Config { pub fn new() -> Self { Self { version: 3, + agent: false, registries: FxHashMap::default(), images: ImageConfig::default(), theme: Theme::Default, @@ -79,7 +81,7 @@ impl Config { Ok(config) => config, Err(e) => error!("Unexpected error occured while parsing config: {}", e), }; - if config.version != 2 { + if config.version != 3 { error!("You are trying to run Cup with an incompatible config file! Please migrate your config file to the version 3, or if you have already done so, add a `version` key with the value `3`.") } config diff --git a/src/server.rs b/src/server.rs index 6d5d435..8dcfd8c 100644 --- a/src/server.rs +++ b/src/server.rs @@ -36,14 +36,18 @@ pub async fn serve(port: &u16, config: &Config) -> std::io::Result<()> { info!("Starting server, please wait..."); let data = ServerData::new(config).await; info!("Ready to start!"); - App::new() + let mut app_builder = App::new() .with_state(Arc::new(Mutex::new(data))) - .at("/", get(handler_service(_static))) .at("/api/v2/json", get(handler_service(api_simple))) .at("/api/v3/json", get(handler_service(api_full))) .at("/api/v2/refresh", get(handler_service(refresh))) - .at("/api/v3/refresh", get(handler_service(refresh))) - .at("/*", get(handler_service(_static))) + .at("/api/v3/refresh", get(handler_service(refresh))); + if !config.agent { + app_builder = app_builder + .at("/", get(handler_service(_static))) + .at("/*", get(handler_service(_static))); + } + app_builder .enclosed(Logger::new()) .serve() .bind(format!("0.0.0.0:{}", port))?