-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
161 lines (113 loc) · 4.28 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
from flask import Flask, send_file, render_template, request, redirect
from debug import request_dump
from PIL import Image
import os
from helpers import foldercheck, genfilename, consolecheck, rendershow
from config import host, loc, debug, secret_key, imglimit, consolelimit, port
app = Flask(__name__)
global latestimg
latestimg = "../static/default.jpg"
@app.route('/')
def main():
global latestimg
if debug == True:
request_dump(request)
useragent = request.headers.get('User-Agent')
consoleraw = consolecheck(useragent)
match consoleraw:
case "n3ds":
console = "a New Nintendo 3DS"
case "wiiu":
console = "a Nintendo Wii U"
case "o3ds":
console = "an Old Nintendo 3DS"
case "ndsi":
console = "a Nintendo DSi"
case "unk":
console = "an unknown device"
case _:
console = "_"
return render_template('index.html', console=console, latestimg=latestimg)
@app.route('/upload', methods=['GET', 'POST'])
def upload():
global latestimg
if debug == True:
request_dump(request)
useragent = request.headers.get('User-Agent')
console = consolecheck(useragent)
if request.method == 'POST':
file = request.files['file']
filename = genfilename(console, file.filename, 8)
img = Image.open(file)
if img.size == (240, 240):
img.save(os.path.join(loc, "qr/", filename))
latestimg = "qr/" + filename
return render_template('complete.html', uploadname="qr/" + filename, url=host)
if console == "unk":
return render_template('error.html', error="You are not uploading from a 3DS/Wii U console.")
if img.size[0] not in [400, 320, 854, 1920, 1360, 1366, 1280]:
return render_template('error.html', error="Image width is incorrect.")
if img.size[1] not in [240, 480, 720, 1080]:
return render_template('error.html', error="Image height is incorrect.")
img.save(os.path.join(loc, filename))
latestimg = filename
return render_template('complete.html', uploadname=filename, url=host)
return render_template('upload.html')
@app.route('/list')
def list():
if debug == True:
request_dump(request)
n3dsimages = []
wiiuimages = []
o3dsimages = []
codeimages = []
for image in os.listdir(loc):
if "n3ds_" in image:
n3dsimages.append(image)
if "wiiu_" in image:
wiiuimages.append(image)
if "o3ds_" in image:
o3dsimages.append(image)
for image in os.listdir(loc + "qr"):
codeimages.append(image)
useragent = request.headers.get('User-Agent')
consoleraw = consolecheck(useragent)
if consoleraw == "unk" and imglimit is not None:
while len(n3dsimages) > imglimit:
n3dsimages.pop()
while len(wiiuimages) > imglimit:
wiiuimages.pop()
while len(o3dsimages) > imglimit:
o3dsimages.pop()
while len(codeimages) > imglimit:
codeimages.pop()
if consoleraw != "unk" and consolelimit is not None:
while len(n3dsimages) > consolelimit:
n3dsimages.pop(-1)
while len(wiiuimages) > consolelimit:
wiiuimages.pop()
while len(o3dsimages) > consolelimit:
o3dsimages.pop()
while len(codeimages) > consolelimit:
codeimages.pop()
showlist = rendershow()
return render_template("list.html", n3dsimages=n3dsimages, wiiuimages=wiiuimages, o3dsimages=o3dsimages, limit=imglimit if consoleraw == "unk" else consolelimit, codeimages=codeimages, showlist=showlist)
@app.route('/uploads/<image>.jpg')
def view(image):
return send_file(f"{loc}/{image}.jpg")
@app.route('/uploads/qr/<image>.jpg')
def viewQR(image):
return send_file(f"{loc}/qr/{image}.jpg")
@app.route('/css/<sheet>.css')
def css(sheet):
return send_file(f"./static/{sheet}.css")
@app.route('/font/<font>')
def woff(font):
if "woff" in font:
return send_file(f"./static/{font}.woff")
if "woff2" in font:
return send_file(f"./static/{font}.woff2")
if __name__ == '__main__':
foldercheck()
app.secret_key = secret_key
app.run(host, port, debug)