diff options
author | 2018-07-29 09:53:01 +0000 | |
---|---|---|
committer | 2018-07-29 09:53:01 +0000 | |
commit | c3cbadf64c1d568e957274e331241691de356f7f (patch) | |
tree | 3c41f029f67adda015590ed6553b1dbf30c2aabf /pysite/views/api/bot/clean.py | |
parent | Fix typo in infractions table definition (diff) | |
parent | Addressing gdude comments (diff) |
Merge branch 'clean_command' into 'master'
Clean command API and frontend
See merge request python-discord/projects/site!26
Diffstat (limited to 'pysite/views/api/bot/clean.py')
-rw-r--r-- | pysite/views/api/bot/clean.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/pysite/views/api/bot/clean.py b/pysite/views/api/bot/clean.py new file mode 100644 index 00000000..82d1e735 --- /dev/null +++ b/pysite/views/api/bot/clean.py @@ -0,0 +1,48 @@ +from flask import jsonify +from schema import Schema + +from pysite.base_route import APIView +from pysite.constants import ValidationTypes +from pysite.decorators import api_key, api_params +from pysite.mixins import DBMixin + +POST_SCHEMA = Schema({ + 'log_data': [ + { + "author": str, + "user_id": str, + "content": str, + "role_id": str, + "timestamp": str, + "embeds": object, + "attachments": [str], + } + ] +}) + + +class CleanView(APIView, DBMixin): + path = '/bot/clean' + name = 'bot.clean' + table_name = 'clean_logs' + + @api_key + @api_params(schema=POST_SCHEMA, validation_type=ValidationTypes.json) + def post(self, data): + """ + Receive some log_data from a bulk deletion, + and store it in the database. + + Returns an ID which can be used to get the data + from the /bot/clean_logs/<id> endpoint. + """ + + # Insert and return the id to use for GET + insert = self.db.insert( + self.table_name, + { + "log_data": data["log_data"] + } + ) + + return jsonify({"log_id": insert['generated_keys'][0]}) |