From df987b400df1b646736fa251dac23d97548df79f Mon Sep 17 00:00:00 2001 From: Jack Eilles Date: Thu, 21 Dec 2023 16:19:22 +0000 Subject: [PATCH] okay passing a string through works now, yippee --- app/routes.py | 12 ++++++++++++ app/worker.py | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/routes.py b/app/routes.py index 0622308..45dbe6c 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,6 +1,8 @@ from app import app, worker from config import Config, Errors from flask import render_template, request, send_file +from werkzeug.datastructures import FileStorage +from io import BytesIO import os import io import random @@ -41,6 +43,16 @@ def index(): return result, status + elif 'file' in request.form: + + file = FileStorage(stream=BytesIO(request.form['file'].encode("utf-8")), filename=id, content_type="text/plain") + + result, status = worker.uploadFile(file, ip, userid, filename, id, retention) + + result = "https://xygt.cc/{}".format(result) + + return result, status + elif 'url' in request.form: result, status = worker.shortURL(url, ip, userid, id, retention) diff --git a/app/worker.py b/app/worker.py index 6c0c8c8..b9b777f 100644 --- a/app/worker.py +++ b/app/worker.py @@ -1,4 +1,5 @@ from config import disallowedMimeTypes, Errors, Config +from werkzeug.datastructures import FileStorage import secrets import magic import datetime @@ -32,7 +33,7 @@ def uploadFile(file, ip, userid, filename, id, retention): elif retention > (Config.minretention+(-Config.maxretention + Config.minretention)*pow((fileSize / Config.maxFileSize -1), 3)): retention = (Config.minretention+(-Config.maxretention + Config.minretention)*pow((fileSize / Config.maxFileSize -1), 3)) - if file. + # Create the file with open(f"{os.path.abspath(Config.fileDir)}/{filename}", "wb") as f: f.write(file.read())