-
Notifications
You must be signed in to change notification settings - Fork 1
/
appsee_watcher.py
41 lines (26 loc) · 1.15 KB
/
appsee_watcher.py
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
import json
from mitmproxy import http, ctx
import re
import uuid
session_id = uuid.uuid4().hex[:24]
def response(flow: http.HTTPFlow) -> None:
global session_id
# config override
if flow.request.url.endswith(".api.appsee.com/config"):
with open("config.json", "rb") as file:
config = json.loads(file.read())
config["SessionId"] = session_id
flow.response.content = json.dumps(config).encode("utf-8")
elif flow.request.url.endswith(".api.appsee.com/upload"):
content = flow.request.content
decoded_content = content.decode("ascii", "backslashreplace")
filename = re.search('filename="(.+?.)"', decoded_content).group(1)
start = decoded_content.index("Content-Type: application/octet-stream")
file_data = content[start + 42:-50]
with open(filename, "ba") as file:
file.write(file_data)
response = json.loads(flow.response.text)
if "VideoUploadPolicy" in response:
response["VideoUploadPolicy"] = 2
flow.response.text = json.dumps(response)
session_id = uuid.uuid4().hex[:24]