sword_layers/servedir/
config.rs1use crate::{DisplayConfig, utils::ByteConfig};
2use console::style;
3use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Debug, Deserialize, Serialize)]
10#[serde(default)]
11pub struct ServeDirConfig {
12 pub enabled: bool,
14
15 #[serde(rename = "static-dir")]
17 pub static_dir: String,
18
19 #[serde(rename = "router-path")]
21 pub router_path: String,
22
23 #[serde(rename = "compression-algorithm")]
25 pub compression_algorithm: Option<String>,
26
27 #[serde(rename = "chunk-size")]
29 pub chunk_size: Option<ByteConfig>,
30
31 #[serde(rename = "not-found-file")]
33 pub not_found_file: Option<String>,
34
35 pub display: bool,
37}
38
39impl Default for ServeDirConfig {
40 fn default() -> Self {
41 ServeDirConfig {
42 enabled: false,
43 static_dir: "public".to_string(),
44 router_path: "/static".to_string(),
45 compression_algorithm: None,
46 chunk_size: None,
47 not_found_file: None,
48 display: false,
49 }
50 }
51}
52
53impl DisplayConfig for ServeDirConfig {
54 fn display(&self) {
55 if !self.display {
56 return;
57 }
58
59 println!("\n{}", style("Serve Directory Configuration:").bold());
60 println!(" ↳ Enabled: {}", self.enabled);
61 println!(" ↳ Static Directory: {}", self.static_dir);
62 println!(" ↳ Router Path: {}", self.router_path);
63
64 if let Some(algorithm) = &self.compression_algorithm {
65 println!(" ↳ Compression Algorithm: {algorithm}");
66 }
67 if let Some(chunk_size) = &self.chunk_size {
68 println!(" ↳ Chunk Size: {}", chunk_size.raw);
69 }
70 if let Some(not_found) = &self.not_found_file {
71 println!(" ↳ Not Found File: {not_found}");
72 }
73 }
74}