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