blob: 2ee3f62d51bdfcfd4097d245493fa577abb0c606 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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": 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]})
|