(error: str = "", form: dict | None = None)
| 194 | |
| 195 | |
| 196 | def build_setup_page(error: str = "", form: dict | None = None) -> str: |
| 197 | form = form or {} |
| 198 | escaped_error = html.escape(error) |
| 199 | escaped_site_name = html.escape( |
| 200 | get_form_value(form, "site_name", DEFAULT_CONFIG["name"]) |
| 201 | ) |
| 202 | escaped_allowed_types = html.escape(get_form_value(form, "allowed_file_types", "*")) |
| 203 | upload_size_value = html.escape(get_form_value(form, "upload_size_value", "10")) |
| 204 | upload_size_unit = get_form_value(form, "upload_size_unit", "MB").upper() |
| 205 | save_time_value = html.escape(get_form_value(form, "save_time_value", "0")) |
| 206 | save_time_unit = get_form_value(form, "save_time_unit", "day") |
| 207 | upload_minute = html.escape( |
| 208 | get_form_value(form, "uploadMinute", str(DEFAULT_CONFIG["uploadMinute"])) |
| 209 | ) |
| 210 | upload_count = html.escape( |
| 211 | get_form_value(form, "uploadCount", str(DEFAULT_CONFIG["uploadCount"])) |
| 212 | ) |
| 213 | error_minute = html.escape( |
| 214 | get_form_value(form, "errorMinute", str(DEFAULT_CONFIG["errorMinute"])) |
| 215 | ) |
| 216 | error_count = html.escape( |
| 217 | get_form_value(form, "errorCount", str(DEFAULT_CONFIG["errorCount"])) |
| 218 | ) |
| 219 | open_upload_checked = ( |
| 220 | " checked" if normalize_bool_field(form, "openUpload", True) else "" |
| 221 | ) |
| 222 | chunk_checked = ( |
| 223 | " checked" if normalize_bool_field(form, "enableChunk", False) else "" |
| 224 | ) |
| 225 | code_generate_type = get_form_value(form, "code_generate_type", "number") |
| 226 | selected_expire_styles = get_form_list(form, "expireStyle") or list( |
| 227 | DEFAULT_CONFIG["expireStyle"] |
| 228 | ) |
| 229 | expire_style_inputs = build_expire_style_inputs(selected_expire_styles) |
| 230 | size_unit_options = "\n".join( |
| 231 | f'<option value="{unit}"{" selected" if unit == upload_size_unit else ""}>{unit}</option>' |
| 232 | for unit in FILE_SIZE_UNITS |
| 233 | ) |
| 234 | save_time_unit_options = "\n".join( |
| 235 | f'<option value="{unit}"{" selected" if unit == save_time_unit else ""}>{label}</option>' |
| 236 | for unit, label in [ |
| 237 | ("second", "秒"), |
| 238 | ("minute", "分钟"), |
| 239 | ("hour", "小时"), |
| 240 | ("day", "天"), |
| 241 | ] |
| 242 | ) |
| 243 | code_type_options = "\n".join( |
| 244 | f'<option value="{value}"{" selected" if value == code_generate_type else ""}>{label}</option>' |
| 245 | for value, label in [("number", "数字"), ("secret", "随机字符")] |
| 246 | ) |
| 247 | error_block = ( |
| 248 | f'<div class="alert" role="alert">{escaped_error}</div>' if escaped_error else "" |
| 249 | ) |
| 250 | return f"""<!doctype html> |
| 251 | <html lang="zh-CN"> |
| 252 | <head> |
| 253 | <meta charset="utf-8"> |
no test coverage detected