about summary refs log tree commit diff
path: root/src/APIv1.py
blob: e0e4848c7c43feab818e2c8aa7f6b060e420012b (plain)
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
import random
from src.socks import *
from ssl import SSLSocket
from src.request import Request


async def respond(client: SSLSocket, request: Request) -> tuple[int, bytes]:
    """
    Respond to clients API request
    """

    # decode API request
    split_path = request.path.split("/")
    api_level1 = split_path[2]
    api_level2 = split_path[3]
    api_request = split_path[4]

    # do something with it (oh god)
    if api_level1 == "file":
        if api_level2 == "generated":
            if api_request == "1gib":
                return 200, random.randbytes(2**30 * 1)
            elif api_request == "5gib":
                return 200, random.randbytes(2**30 * 5)
            elif api_request == "10gib":
                return 200, random.randbytes(2**30 * 10)
            elif api_request == "20gib":
                return 200, random.randbytes(2**30 * 20)
            else:
                return 400, b''
        else:
            return 400, b''
    else:
        return 400, b''