diff options
| author | Jakob L. Kreuze | 2025-10-12 15:05:48 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze | 2025-10-12 15:05:48 -0400 |
| commit | 1bec9ce49f85673a72e0fb78eb9a414309f7e64d (patch) | |
| tree | 3227f6da079bcdfea0c9546237ba243792b3c6b7 /server/szurubooru | |
| parent | 30d54bbd7afdac9b34b247b22de93737987cd396 (diff) | |
Replace outdated `cgi` module
Diffstat (limited to 'server/szurubooru')
| -rw-r--r-- | server/szurubooru/rest/app.py | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/server/szurubooru/rest/app.py b/server/szurubooru/rest/app.py index c098bd0..26bbc44 100644 --- a/server/szurubooru/rest/app.py +++ b/server/szurubooru/rest/app.py @@ -1,4 +1,4 @@ -import cgi +from multipart import parse_form_data, is_form_request import json import re import urllib.parse @@ -40,15 +40,11 @@ def _create_context(env: Dict[str, Any]) -> context.Context: files = {} params = dict(urllib.parse.parse_qsl(env.get("QUERY_STRING", ""))) - if "multipart" in env.get("CONTENT_TYPE", ""): - form = cgi.FieldStorage(fp=env["wsgi.input"], environ=env) - if not form.list: - raise errors.HttpBadRequest( - "ValidationError", "No files attached." - ) - body = form.getvalue("metadata") - for key in form: - files[key] = form.getvalue(key) + if is_form_request(env): + _, files = parse_form_data(env) + files = {n: f.raw for (n, f) in files.items()} + body = files["metadata"] + print(files) else: body = env["wsgi.input"].read() |