shared/settings/
server.rs1use super::{
2 ExtensionSettings, SettingsDeserializeExt, SettingsDeserializer, SettingsSerializeExt,
3 SettingsSerializer,
4};
5use compact_str::ToCompactString;
6use serde::{Deserialize, Serialize};
7use utoipa::ToSchema;
8
9#[derive(Clone, ToSchema, Serialize, Deserialize)]
10pub struct AppSettingsServer {
11 pub max_file_manager_view_size: u64,
12 pub max_file_manager_content_search_size: u64,
13 pub max_file_manager_search_results: u64,
14 pub max_subuser_count: u64,
15 pub max_schedule_step_count: u64,
16
17 pub allow_overwriting_custom_docker_image: bool,
18 pub allow_viewing_installation_logs: bool,
19 pub allow_acknowledging_installation_failure: bool,
20 pub allow_viewing_transfer_progress: bool,
21
22 pub container_prelude: compact_str::CompactString,
23}
24
25#[async_trait::async_trait]
26impl SettingsSerializeExt for AppSettingsServer {
27 async fn serialize(
28 &self,
29 serializer: SettingsSerializer,
30 ) -> Result<SettingsSerializer, anyhow::Error> {
31 Ok(serializer
32 .write_raw_setting(
33 "max_file_manager_view_size",
34 self.max_file_manager_view_size.to_compact_string(),
35 )
36 .write_raw_setting(
37 "max_file_manager_content_search_size",
38 self.max_file_manager_content_search_size
39 .to_compact_string(),
40 )
41 .write_raw_setting(
42 "max_file_manager_search_results",
43 self.max_file_manager_search_results.to_compact_string(),
44 )
45 .write_raw_setting(
46 "max_subuser_count",
47 self.max_subuser_count.to_compact_string(),
48 )
49 .write_raw_setting(
50 "max_schedule_step_count",
51 self.max_schedule_step_count.to_compact_string(),
52 )
53 .write_raw_setting(
54 "allow_overwriting_custom_docker_image",
55 self.allow_overwriting_custom_docker_image
56 .to_compact_string(),
57 )
58 .write_raw_setting(
59 "allow_viewing_installation_logs",
60 self.allow_viewing_installation_logs.to_compact_string(),
61 )
62 .write_raw_setting(
63 "allow_acknowledging_installation_failure",
64 self.allow_acknowledging_installation_failure
65 .to_compact_string(),
66 )
67 .write_raw_setting(
68 "allow_viewing_transfer_progress",
69 self.allow_viewing_transfer_progress.to_compact_string(),
70 )
71 .write_raw_setting("container_prelude", &*self.container_prelude))
72 }
73}
74
75pub struct AppSettingsServerDeserializer;
76
77#[async_trait::async_trait]
78impl SettingsDeserializeExt for AppSettingsServerDeserializer {
79 async fn deserialize_boxed(
80 &self,
81 mut deserializer: SettingsDeserializer<'_>,
82 ) -> Result<ExtensionSettings, anyhow::Error> {
83 Ok(Box::new(AppSettingsServer {
84 max_file_manager_view_size: deserializer
85 .take_raw_setting("max_file_manager_view_size")
86 .and_then(|s| s.parse().ok())
87 .unwrap_or(10 * 1024 * 1024),
88 max_file_manager_content_search_size: deserializer
89 .take_raw_setting("max_file_manager_content_search_size")
90 .and_then(|s| s.parse().ok())
91 .unwrap_or(5 * 1024 * 1024),
92 max_file_manager_search_results: deserializer
93 .take_raw_setting("max_file_manager_search_results")
94 .and_then(|s| s.parse().ok())
95 .unwrap_or(100),
96 max_subuser_count: deserializer
97 .take_raw_setting("max_subuser_count")
98 .and_then(|s| s.parse().ok())
99 .unwrap_or(25),
100 max_schedule_step_count: deserializer
101 .take_raw_setting("max_schedule_step_count")
102 .and_then(|s| s.parse().ok())
103 .unwrap_or(50),
104 allow_overwriting_custom_docker_image: deserializer
105 .take_raw_setting("allow_overwriting_custom_docker_image")
106 .map(|s| s == "true")
107 .unwrap_or(true),
108 allow_viewing_installation_logs: deserializer
109 .take_raw_setting("allow_viewing_installation_logs")
110 .map(|s| s == "true")
111 .unwrap_or(true),
112 allow_acknowledging_installation_failure: deserializer
113 .take_raw_setting("allow_acknowledging_installation_failure")
114 .map(|s| s == "true")
115 .unwrap_or(true),
116 allow_viewing_transfer_progress: deserializer
117 .take_raw_setting("allow_viewing_transfer_progress")
118 .map(|s| s == "true")
119 .unwrap_or(true),
120 container_prelude: deserializer
121 .take_raw_setting("container_prelude")
122 .unwrap_or_else(|| "container@calagopus~".into()),
123 }))
124 }
125}