initial
This commit is contained in:
commit
40c7c079bd
9
Dockerfile
Normal file
9
Dockerfile
Normal file
@ -0,0 +1,9 @@
|
||||
FROM python:3.8-slim
|
||||
RUN mkdir /app
|
||||
WORKDIR /app
|
||||
ADD requirements.txt /app
|
||||
RUN pip3 install -r requirements.txt
|
||||
ADD . /app
|
||||
EXPOSE 5000
|
||||
RUN chmod +x ./entrypoint.sh
|
||||
ENTRYPOINT ["sh", "entrypoint.sh"]
|
||||
70
app/app.py
Normal file
70
app/app.py
Normal file
@ -0,0 +1,70 @@
|
||||
from flask import Flask, abort, request, send_file
|
||||
from pprint import pprint
|
||||
|
||||
import os.path
|
||||
import string
|
||||
import random
|
||||
useSpecialChars = False
|
||||
basePath="/app"
|
||||
domain = "https://upload.lovelynet.net"
|
||||
|
||||
letters = string.ascii_letters
|
||||
if useSpecialChars:
|
||||
letters = letters + string.punctuation
|
||||
|
||||
# Functions
|
||||
def randomName(nameLength, ext):
|
||||
name = ""
|
||||
for x in range(0,nameLength):
|
||||
num = random.randint(0,len(letters))
|
||||
#print(num)
|
||||
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 request.form['type'] == 'img':
|
||||
name = randomName(5, "png")
|
||||
saveIMG(request.files['image.png'], name)
|
||||
|
||||
if request.form['type'] == 'file':
|
||||
print(request.files['video.mp4'])
|
||||
name = randomName(5, "mp4")
|
||||
saveIMG(request.files['video.mp4'], name)
|
||||
return f"{domain}/{name}"
|
||||
except:
|
||||
return ""
|
||||
|
||||
@app.route('/<path:path>')
|
||||
def getImage(path):
|
||||
if (checkFileExists(path)):
|
||||
return send_file(f"{basePath}/imgs/{path}")
|
||||
abort(404)
|
||||
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(error):
|
||||
return "File not found", 404
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0')
|
||||
4
app/wsgi.py
Normal file
4
app/wsgi.py
Normal file
@ -0,0 +1,4 @@
|
||||
from .app import app
|
||||
|
||||
# do some production specific things to the app
|
||||
app.config['DEBUG'] = False
|
||||
2
entrypoint.sh
Normal file
2
entrypoint.sh
Normal file
@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
exec gunicorn --config /app/gunicorn_config.py app.wsgi:app
|
||||
4
gunicorn_config.py
Normal file
4
gunicorn_config.py
Normal file
@ -0,0 +1,4 @@
|
||||
bind = "0.0.0.0:5000"
|
||||
workers = 4
|
||||
threads = 4
|
||||
timeout = 120
|
||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
flask
|
||||
gunicorn
|
||||
Loading…
x
Reference in New Issue
Block a user