in
Clone
https://git.tahinli.com/Tahinli/in.git
0 watching0 forksRustAGPL-3.0528.7 KiB9215377Tahinli27 days ago37 commits
| 1 | //! Runtime settings: the operator's values that change without a restart, and where each one comes from. |
| 2 | //! |
| 3 | //! The precedence is fixed: a UI override (a row of the `settings` table, written by the admin page), then |
| 4 | //! the file (`[limits]` in the configuration), then the built-in default. [`resolve`] returns the value |
| 5 | //! together with the layer it came from, so the admin page can show the source beside each value. Every |
| 6 | //! caller reads through [`resolve`], so the rule is written once. Nothing here changes the database. |
| 7 | |
| 8 | use crateLimits; |
| 9 | use crate; |
| 10 | use crateDEFAULT_MEMBER_QUOTA; |
| 11 | use crateStore; |
| 12 | use crateDEFAULT_SERVICE_QUOTA; |
| 13 | |
| 14 | /// Settings key of the quota a new person gets, in bytes. |
| 15 | pub const DEFAULT_QUOTA_KEY: &str = "default_quota_bytes"; |
| 16 | /// Settings key of the quota a new service namespace gets, in bytes. |
| 17 | pub const DEFAULT_SERVICE_QUOTA_KEY: &str = "default_service_quota_bytes"; |
| 18 | /// Settings key of the days trash waits before a purge. |
| 19 | pub const PURGE_KEY: &str = "purge_after_days"; |
| 20 | /// Settings key of the largest upload, in bytes. |
| 21 | pub const MAX_UPLOAD_KEY: &str = "max_upload_bytes"; |
| 22 | /// Settings key of the longest share link, in days. |
| 23 | pub const LINK_MAX_DAYS_KEY: &str = "link_max_days"; |
| 24 | |
| 25 | /// One GiB in bytes. |
| 26 | const GIB: i64 = 1024 * 1024 * 1024; |
| 27 | /// One MiB in bytes. |
| 28 | const MIB: i64 = 1024 * 1024; |
| 29 | /// One TiB in bytes: the upper bound of every byte value, far above any real quota. |
| 30 | const TIB: i64 = 1024 * GIB; |
| 31 | |
| 32 | /// Default purge delay: 30 days. |
| 33 | pub const DEFAULT_PURGE_AFTER_DAYS: i64 = 30; |
| 34 | /// Default largest upload: 50 GiB. |
| 35 | pub const DEFAULT_MAX_UPLOAD: i64 = 50 * GIB; |
| 36 | /// Default longest share link: a year. |
| 37 | pub const DEFAULT_LINK_MAX_DAYS: i64 = 365; |
| 38 | |
| 39 | /// How a field may change. Shown on the admin page next to the value. |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | /// The layer a value came from. |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | /// A value and the layer it came from. |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | /// One field the admin page can show or change: its key, default, the bounds a value must meet, and its |
| 71 | /// mode. Byte fields are in bytes and day fields in days. |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | /// Every field of the admin page's defaults section, in display order. |
| 87 | pub const FIELDS: = |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | ; |
| 124 | |
| 125 | /// The field with this key, if it is one of [`FIELDS`]. |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | /// The file value of `key`, when the `[limits]` table sets it. |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | /// Checks a value against the field's bounds. The refusal word is the key with `_range`, which the |
| 143 | /// admin page turns into a sentence. |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | /// Parses the text of an admin form for `key`. Blank means "no override": `Ok(None)`. Anything else |
| 152 | /// must be an integer within the field's bounds. |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | /// Checks every value the file sets. Called by `Config::validate`, so a bad file fails at boot. |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | /// The effective value of `key`: the UI override when one is stored and valid, else the file value, else |
| 181 | /// the default. A stored override that is out of bounds (possible only by hand-editing the database) is |
| 182 | /// ignored and the next layer is used. |
| 183 | pub async |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | /// The word the admin page shows for a source: `ui`, `file` or `default`. The page translates it. |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 |