-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
38 lines (26 loc) · 917 Bytes
/
main.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
from bottle import Bottle, static_file, request, response
import json
import base64
app = Bottle()
STATIC_PATH = "./static"
@app.get("/")
def index():
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "0"
return static_file("./static/data.txt", root="./")
@app.get("/static/<filename:path>")
def server_static(filename):
return static_file(filename, root=STATIC_PATH)
@app.get("/admin")
def get_admin():
return static_file("index.html", root=STATIC_PATH)
@app.post("/admin")
def post_admin():
body = request.body.read()
links = json.loads(body.decode("utf-8"))["links"]
with open("./static/data.txt", "wb") as txt:
txt.write(base64.b64encode(links.encode("utf-8")))
return "success"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=80, server="paste")