This repository has been archived by the owner on May 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
99 lines (87 loc) · 4.1 KB
/
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
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
from flask import Flask, render_template, request
import hurry.filesize, secrets, json, os
from os.path import splitext
from PIL import Image
import config
from config import version, api_key, description, domain, port, uploader_name, keywords, logo, website ,author_name, storage_folder, github, discord
from getversion import versiondata
from getchangelog import string1
print("[KOOLIMGS] Starting KoolIMGS..")
print("[KOOLIMGS] Checking version..")
if version == versiondata:
print("[KOOLIMGS] You are up to date your version is", versiondata)
app = Flask(__name__)
print("[KOOLIMGS] Loading Pages...")
@app.route('/')
def index():
return render_template('index.html',embeddsc=description ,keyemwords=keywords, websitelogo=logo,uploaderhostname=uploader_name, URL=domain, git=github, websiteurl=website, dsc=discord)
@app.route('/info')
def info():
return render_template('svinfo.html', keyemwords=keywords, websitelogo=logo, uploaderhostname=uploader_name, URL=domain, git=github, websiteurl=website, dsc=discord)
@app.route('/<page>')
def screenshoturl(page):
if f'{page}.png' not in os.listdir(storage_folder):
return render_template('404.html', URL=domain)
uploader = 'N/A'
try:
with open(f'static/screenshots/json/{page}.json') as f:
uploader = json.load(f)["author_name"]
except Exception as e:
print(e)
pass
return render_template('sstemplate.html',
ss_location=f'{domain}/static/screenshots/images/{page}.png',
json_location=f'{domain}/static/screenshots/json/{page}.json',
upload_username=uploader,
uploaderhostname=uploader_name,
cur_url=page, git=github, websiteurl=website, dsc=discord, keyemwords=keywords, websitelogo=logo)
@app.route('/upload', methods=['POST'])
def upload():
if not request.method == 'POST':
return {"error": "Method Not Allowed"}, 405
used_api_key = request.form.to_dict(flat=False)['secret_key'][0]
if used_api_key == api_key:
file = request.files['image']
extension = splitext(file.filename)[1]
file.flush()
size = os.fstat(file.fileno()).st_size
if extension != '.png':
return 'File type is not supported', 415
elif size > 6000000:
return 'File size too large', 400
else:
image = Image.open(file)
data = list(image.getdata())
file_without_exif = Image.new(image.mode, image.size)
file_without_exif.putdata(data)
filename = secrets.token_urlsafe(8)
file_without_exif.save(os.path.join(storage_folder, filename + extension))
image_json = {"title": uploader_name,
"author_name": author_name,
"author_url": domain,
"provider_name": hurry.filesize.size(size, system=hurry.filesize.alternative)}
with open(f'./static/screenshots/json/{filename}.json', 'w+') as f:
json.dump(image_json, f, indent=4)
return json.dumps({"filename": filename, "extension": extension}), 200
else:
return 'Unauthorized use', 401
@app.route('/delete')
def delete():
del_url = request.args.get('del_url')
used_api_key = request.args.get('api_key')
if f"{del_url}.png" in os.listdir('./static/screenshots/images'):
if used_api_key == api_key:
os.remove(f'./static/screenshots/images/{del_url}.png')
os.remove(f'./static/screenshots/json/{del_url}.json')
return render_template('succes.html', URL=domain), 200
else:
return render_template('faild.html', URL=domain), 401
else:
return render_template('404.html', URL=domain), 404
print("[KOOLIMGS] Loading webserver..")
print("[KOOLIMGS] Starting webserver on", port)
app.run("0.0.0.0", port)
print("[KOOLIMGS] DONE")
else:
print("You have to update KoolIMGS")
print("You have the version",version, "and you need to update to", versiondata)