Added config and env support for settings
This commit is contained in:
parent
0d6f4fe4e0
commit
f7720d7409
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
env/
|
||||
.vscode/
|
||||
41
app/app.py
41
app/app.py
@ -1,47 +1,63 @@
|
||||
from flask import Flask, abort, request, send_file
|
||||
from pprint import pprint
|
||||
|
||||
import os.path
|
||||
import os
|
||||
import string
|
||||
import random
|
||||
useSpecialChars = False
|
||||
basePath="/app"
|
||||
domain = "https://upload.lovelynet.net"
|
||||
import configparser
|
||||
|
||||
basePath = "/app"
|
||||
# domain = "https://upload.lovelynet.net"
|
||||
# secret = "thisistheshit"
|
||||
|
||||
letters = string.ascii_letters
|
||||
if useSpecialChars:
|
||||
letters = letters + string.punctuation
|
||||
if os.environ.get('UPDOMAIN') and os.environ.get('UPSECRET'):
|
||||
domain = os.environ.get('UPDOMAIN')
|
||||
secret = os.environ.get('UPSECRET')
|
||||
else:
|
||||
config = configparser.ConfigParser()
|
||||
config.read('app/config.ini')
|
||||
|
||||
domain = config['VARS']['domain']
|
||||
secret = config['VARS']['secret']
|
||||
|
||||
print(domain, secret)
|
||||
# Functions
|
||||
|
||||
|
||||
def randomName(nameLength, ext):
|
||||
name = ""
|
||||
for x in range(0,nameLength):
|
||||
num = random.randint(0,len(letters))
|
||||
#print(num)
|
||||
for x in range(0, nameLength):
|
||||
num = random.randint(0, len(letters))
|
||||
name += letters[num - 1]
|
||||
name = checkDuplicateName(name, ext)
|
||||
return f"{name}.{ext}"
|
||||
|
||||
|
||||
def checkDuplicateName(name, ext):
|
||||
if os.path.isfile(f'{basePath}/imgs/{name}.{ext}'):
|
||||
name = randomName(5, ext)
|
||||
return name
|
||||
|
||||
|
||||
def checkFileExists(name):
|
||||
if os.path.isfile(f'{basePath}/imgs/{name}'):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def saveIMG(imageData, name):
|
||||
imageData.save(f'{basePath}/imgs/' + name)
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['DEBUG'] = True
|
||||
|
||||
|
||||
@app.route('/', methods=['POST', 'GET'])
|
||||
def index():
|
||||
try:
|
||||
if 'thisistheshit' in request.headers['X-AUTH']:
|
||||
if secret in request.headers['X-AUTH']:
|
||||
if request.form['type'] == 'img':
|
||||
name = randomName(5, "png")
|
||||
saveIMG(request.files['image.png'], name)
|
||||
@ -54,6 +70,7 @@ def index():
|
||||
except:
|
||||
return ""
|
||||
|
||||
|
||||
@app.route('/<path:path>')
|
||||
def getImage(path):
|
||||
if (checkFileExists(path)):
|
||||
@ -66,5 +83,5 @@ def page_not_found(error):
|
||||
return "File not found", 404
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0')
|
||||
# if __name__ == '__main__':
|
||||
# app.run(host='0.0.0.0')
|
||||
|
||||
3
app/config.ini
Normal file
3
app/config.ini
Normal file
@ -0,0 +1,3 @@
|
||||
[VARS]
|
||||
domain = https://this.domain.tld
|
||||
secret = secretcode
|
||||
Loading…
x
Reference in New Issue
Block a user