diff options
author | Andrew Godwin | 2022-12-10 21:03:14 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-12-12 11:56:49 -0700 |
commit | 1017c71ba1d80a1690e357a938ad46f246a456ae (patch) | |
tree | ffe6172f5f38bb1c8aac3c42ada272bba40348e7 /api/parser.py | |
parent | a8d1450763bea6f8d5388633b62a92c7d89913b6 (diff) | |
download | takahe-1017c71ba1d80a1690e357a938ad46f246a456ae.tar.gz takahe-1017c71ba1d80a1690e357a938ad46f246a456ae.tar.bz2 takahe-1017c71ba1d80a1690e357a938ad46f246a456ae.zip |
Working start of an OAuth flow
Diffstat (limited to 'api/parser.py')
-rw-r--r-- | api/parser.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/api/parser.py b/api/parser.py new file mode 100644 index 0000000..63e283f --- /dev/null +++ b/api/parser.py @@ -0,0 +1,20 @@ +import json + +from ninja.parser import Parser + + +class FormOrJsonParser(Parser): + """ + If there's form data in a request, makes it into a JSON dict. + This is needed as the Mastodon API allows form data OR json body as input. + """ + + def parse_body(self, request): + # Did they submit JSON? + if request.content_type == "application/json": + return json.loads(request.body) + # Fall back to form data + value = {} + for key, item in request.POST.items(): + value[key] = item + return value |