diff --git a/.gitignore b/.gitignore index 0dbf2f2..f5905ad 100644 --- a/.gitignore +++ b/.gitignore @@ -168,3 +168,5 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +_identifierAllocation.db +data/ \ No newline at end of file diff --git a/_map.db b/_map.db new file mode 100644 index 0000000..8f4412e Binary files /dev/null and b/_map.db differ diff --git a/index.html b/index.html index b7ae71f..36e1d50 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,9 @@ Filehosting Panel - +
+ + +
- \ No newline at end of file + \ No newline at end of file diff --git a/main.py b/main.py index b0b5b9f..e32f00c 100644 --- a/main.py +++ b/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/") def downloader(identifier): - return "identifier: " + escape(identifier) \ No newline at end of file + 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" \ No newline at end of file