From 94f8dfe6fdae2bf4b02c94dca792692bf19d0128 Mon Sep 17 00:00:00 2001 From: raizenxd Date: Sat, 22 Mar 2025 13:58:12 +0100 Subject: [PATCH] big update lol --- .gitignore | 2 ++ _map.db | Bin 0 -> 12288 bytes index.html | 7 ++++-- main.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 60 insertions(+), 10 deletions(-) create mode 100644 _map.db 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 0000000000000000000000000000000000000000..8f4412eaa5e6f1222b46776c504d72a6aaba8d62 GIT binary patch literal 12288 zcmeI$L2uJA6bEoSMGPiQfzyt)#D$8ktK--SJ5eB$D!K|v4(lm$8XI|Pn?X~Axb@8E z;_Gnch%;#woOa=W(ErI+-isY4`Q7aI?%+{Y)x?zGmB9xLBj1fWt-#fnF2KC9k z+rnSl`mPAb;Pbbm@FxjEK|&FJzv}^vLjVF0fB*y_009U<00Izz00jOKfn7)sj=NpD zTQ#~|n!;6ieeQlsf>*O_lxHj-y_{rhKhB=Iisjj5&fd<(7o*vny~*Z%R+&xX*1B=^ z`ewAxw%5yASGijm_S&zLk1w)5v;GZJ?QgX!_&FQ1nHbx!@ig!8;Qn#erNpf(^JVjK z>38&n-Zu43UF<)g;QO@Q*FR`Ik9?=$SK=E20uX=z1Rwwb2tWV=5P$##AOL~CF0kv+ zgWm3mct)j~D#s^0xtw3gbZ}bfMxV-52%Z|LxmpOD4&%i_+M$V+Duv?DW0fY{CTWtW zDz&lIFilehosting 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