-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
44 lines (34 loc) · 1.22 KB
/
app.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
40
41
42
43
44
from flask import Flask, send_file
import os
app = Flask(__name__)
@app.errorhandler(404)
def not_found(e):
return ("<p>Skin or page not found ({path}).</p>").format(path=e), 404
@app.route("/list")
def list():
skinpath = os.path.join(app.root_path + "/skins")
files = [
f for f in os.listdir(skinpath) if os.path.isfile(os.path.join(skinpath, f))
]
return ("<p>{count} skins</p><code>{list}</code>").format(
count=len(files), list=("<br>").join(sorted(files))
)
@app.route("/")
def info():
return "<p>Search for a skin by providing a filename.</p><p>Submit new skins via. email (<a href=mailto://ewangreen95@gmail.com>ewangreen95@gmail.com</a>) or Discord (mpft)</p>"
@app.route("/<skin>")
def find(skin):
if not skin.endswith(".png"):
skin += ".png"
skin = os.path.join("skins/" + skin)
if not os.path.isfile(os.path.join(app.root_path, skin)):
return not_found(skin)
return send_file(skin)
@app.route("/fix/<skin>")
def find_fixed(skin):
if not skin.endswith(".png"):
skin += ".png"
skin = os.path.join("skins_fixed/" + skin)
if not os.path.isfile(os.path.join(app.root_path, skin)):
return not_found(skin)
return send_file(skin)