MCPcopy Index your code
hub / github.com/vastsa/FileCodeBox / parse_setup_options

Function parse_setup_options

main.py:135–182  ·  view source on GitHub ↗
(data: dict)

Source from the content-addressed store, hash-verified

133
134
135def parse_setup_options(data: dict) -> dict:
136 upload_size_unit = get_form_value(data, "upload_size_unit", "MB").upper()
137 if upload_size_unit not in FILE_SIZE_UNITS:
138 raise ValueError("文件大小单位不正确")
139 upload_size_value = parse_int_field(
140 data, "upload_size_value", 10, "文件大小限制", min_value=1
141 )
142
143 save_time_unit = get_form_value(data, "save_time_unit", "day")
144 if save_time_unit not in SAVE_TIME_UNITS:
145 raise ValueError("最长保存时间单位不正确")
146 save_time_value = parse_int_field(
147 data, "save_time_value", 0, "最长保存时间", min_value=0
148 )
149
150 expire_styles = get_form_list(data, "expireStyle")
151 valid_expire_styles = {style for style, _label in EXPIRE_STYLE_OPTIONS}
152 expire_styles = [style for style in expire_styles if style in valid_expire_styles]
153 if not expire_styles:
154 raise ValueError("至少需要选择一种过期方式")
155
156 code_generate_type = get_form_value(data, "code_generate_type", "number")
157 if code_generate_type not in {"number", "secret"}:
158 raise ValueError("提取码类型不正确")
159
160 return {
161 "allowed_file_types": parse_allowed_file_types(
162 get_form_value(data, "allowed_file_types", "*")
163 ),
164 "code_generate_type": code_generate_type,
165 "enableChunk": int(normalize_bool_field(data, "enableChunk", False)),
166 "errorCount": parse_int_field(
167 data, "errorCount", DEFAULT_CONFIG["errorCount"], "取件错误次数限制", 1
168 ),
169 "errorMinute": parse_int_field(
170 data, "errorMinute", DEFAULT_CONFIG["errorMinute"], "取件错误检测窗口", 1
171 ),
172 "expireStyle": expire_styles,
173 "max_save_seconds": save_time_value * SAVE_TIME_UNITS[save_time_unit],
174 "openUpload": int(normalize_bool_field(data, "openUpload", True)),
175 "uploadCount": parse_int_field(
176 data, "uploadCount", DEFAULT_CONFIG["uploadCount"], "上传次数限制", 1
177 ),
178 "uploadMinute": parse_int_field(
179 data, "uploadMinute", DEFAULT_CONFIG["uploadMinute"], "上传检测窗口", 1
180 ),
181 "uploadSize": upload_size_value * FILE_SIZE_UNITS[upload_size_unit],
182 }
183
184
185def build_expire_style_inputs(selected_styles: list[str]) -> str:

Calls 5

get_form_valueFunction · 0.85
parse_int_fieldFunction · 0.85
get_form_listFunction · 0.85
parse_allowed_file_typesFunction · 0.85
normalize_bool_fieldFunction · 0.85