big update lol
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -168,3 +168,5 @@ cython_debug/
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
_identifierAllocation.db
|
||||
data/
|
||||
@@ -6,6 +6,9 @@
|
||||
<title>Filehosting Panel</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<form action="./upload" method="post" enctype="multipart/form-data">
|
||||
<input type="file" name="file"/>
|
||||
<input type="submit" value="Upload">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
61
main.py
61
main.py
@@ -1,18 +1,63 @@
|
||||
from flask import send_file, Flask
|
||||
#from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
from markupsafe import escape
|
||||
from flask import send_file, Flask, request
|
||||
#from werkzeug.middleware.proxy_fix import ProxyFix # Für Einsatz in Produktion
|
||||
import sqlite3, hashlib, random, os, pathlib
|
||||
|
||||
app = Flask(__name__)
|
||||
#app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1)
|
||||
#app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1) # Für Einsatz in Produktion
|
||||
|
||||
db = sqlite3.connect("_map.db", check_same_thread=False)
|
||||
dbCursor = db.cursor()
|
||||
dbCursor.execute("CREATE TABLE IF NOT EXISTS _idToFile (id TEXT PRIMARY KEY, destination TEXT, uploadTime DATETIME, fileName TEXT, usesLeft INT);")
|
||||
|
||||
if pathlib.Path("./data").is_dir() == False:
|
||||
os.mkdir("data")
|
||||
|
||||
@app.route("/")
|
||||
def mainpage():
|
||||
return "no i chuj"
|
||||
return send_file("index.html")
|
||||
|
||||
@app.route("/upload")
|
||||
@app.route("/upload", methods = ["POST"])
|
||||
def uploader():
|
||||
return "ebebe"
|
||||
file = request.files['file'] #
|
||||
name = file.filename.rsplit(".", 1)
|
||||
|
||||
idValue = ""
|
||||
idIsUnique = False
|
||||
|
||||
while idIsUnique == False:
|
||||
|
||||
if idValue != "":
|
||||
idValue = ""
|
||||
|
||||
for _ in range(14):
|
||||
vArray = [""] * 3
|
||||
vArray[0] = chr(random.randint(48, 57)) # 0 - 9
|
||||
vArray[1] = chr(random.randint(65, 90)) # A - Z
|
||||
vArray[2] = chr(random.randint(97, 122)) # a - z
|
||||
|
||||
selector = random.randint(0,2)
|
||||
idValue += vArray[selector]
|
||||
|
||||
dbCursor.execute("SELECT * FROM _idToFile WHERE id=?;", (idValue,))
|
||||
if dbCursor.fetchone() == None:
|
||||
idIsUnique = True
|
||||
|
||||
if (len(name) > 1): # Dateinamen die ein Suffix besitzen
|
||||
path = f"./data/{hashlib.sha256((name[0] + idValue).encode()).hexdigest()}.{name[1]}"
|
||||
else: # Dateinamen die kein Suffix besitzen
|
||||
path = f"./data/{hashlib.sha256((name[0] + idValue).encode()).hexdigest()}"
|
||||
|
||||
file.save(path)
|
||||
dbCursor.execute("INSERT INTO _idToFile VALUES (?, ?, datetime('now'), ?, ?);", (idValue, path, file.filename, 10))
|
||||
db.commit()
|
||||
|
||||
return "sank you"
|
||||
|
||||
@app.route("/download/<string:identifier>")
|
||||
def downloader(identifier):
|
||||
return "identifier: " + escape(identifier)
|
||||
dbCursor.execute("SELECT destination FROM _idToFile WHERE id=?;", (identifier,))
|
||||
path = dbCursor.fetchone()
|
||||
if path != None:
|
||||
return send_file(path[0])
|
||||
else:
|
||||
return "no file, now fuck off"
|
||||
Reference in New Issue
Block a user