Rework with UI in mind
Some checks failed
/ backend-pylint (push) Successful in 1m37s
/ publish-artifacts (push) Successful in 1m28s
/ build-artifacts (push) Successful in 16s
/ build-and-push-container (push) Successful in 2m46s
/ release (push) Failing after 34m50s

This commit is contained in:
Firq 2024-10-03 21:34:46 +02:00
parent fbdb6f9f5a
commit 27fd95ba1e
Signed by: Firq
GPG key ID: 3ACC61C8CEC83C20
4 changed files with 5 additions and 58 deletions

View file

@ -1,6 +1,6 @@
[project] [project]
name = "support_formatter" name = "support_formatter"
version = "0.1.0-a.2" version = "0.1.0"
requires-python = ">= 3.10" requires-python = ">= 3.10"
authors = [{name = "Firq", email = "firelp42@gmail.com"}] authors = [{name = "Firq", email = "firelp42@gmail.com"}]
maintainers = [{name = "Firq", email = "firelp42@gmail.com"}] maintainers = [{name = "Firq", email = "firelp42@gmail.com"}]

View file

@ -1,14 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Support File Converter - Error</title>
</head>
<body>
<h1>Error</h1>
</body>
</html>

View file

@ -1,34 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Support File Converter</title>
</head>
<body>
<h1>Convert to Nerone-compatible data</h1>
<form method=post enctype=multipart/form-data>
<label for="fusername">Username:</label>
<input type="text" id="fusername" name="username" placeholder="Your username">
<br />
<label for="ffriendcode">Friendcode:</label>
<input type="text" id="ffriendcode" name="friendcode" placeholder="000,000,000">
<br />
<br />
<label for="fservantdata">Servant Data</label>
<br />
<input type="file" id="fservantdata" name="servantdata">
<br />
<br />
<label for="fcedata">CE Data (optional)</label>
<br />
<input type="file" id="fcedata" name="cedata">
<br />
<br />
<input type="submit" value="Upload">
</form>
</body>
</html>

View file

@ -1,7 +1,6 @@
import os import os
import pathlib import pathlib
from typing import List from typing import List
from flask import send_from_directory
import marshmallow as ma import marshmallow as ma
from flask_smorest.fields import Upload from flask_smorest.fields import Upload
from werkzeug.datastructures import FileStorage from werkzeug.datastructures import FileStorage
@ -26,7 +25,7 @@ class MultipartFileSchema(ma.Schema):
servantdata = Upload() servantdata = Upload()
cedata = Upload() cedata = Upload()
@blp.route("/", methods=["POST"]) @blp.route("/upload", methods=["POST"])
@blp.arguments(MultipartFormSchema, location="form") @blp.arguments(MultipartFormSchema, location="form")
@blp.arguments(MultipartFileSchema, location="files") @blp.arguments(MultipartFileSchema, location="files")
@blp.response(200) @blp.response(200)
@ -39,7 +38,7 @@ def upload_file(form: dict[str, str], files: dict[str, FileStorage]):
for name, file in files.items(): for name, file in files.items():
if name not in ("servantdata", "cedata"): if name not in ("servantdata", "cedata"):
return send_from_directory(APISettings.PAGES_DIRECTORY, "error.html") return { "status": 406, "message": "Invalid form sent" }, 406
filepath = APISettings.FILE_SAVE_DIRECTORY / f"{uuid.uuid4()}.csv" filepath = APISettings.FILE_SAVE_DIRECTORY / f"{uuid.uuid4()}.csv"
file.save(filepath) file.save(filepath)
@ -51,7 +50,7 @@ def upload_file(form: dict[str, str], files: dict[str, FileStorage]):
filepaths.append(filepath) filepaths.append(filepath)
if len(filepaths) == 0: if len(filepaths) == 0:
return send_from_directory(APISettings.PAGES_DIRECTORY, "error.html") return { "status": 406, "message": "No files provided" }, 406
try: try:
for f in filepaths: for f in filepaths:
@ -61,10 +60,6 @@ def upload_file(form: dict[str, str], files: dict[str, FileStorage]):
except FileTypeInvalidError: except FileTypeInvalidError:
for f in filepaths: for f in filepaths:
f.unlink() f.unlink()
return send_from_directory(APISettings.PAGES_DIRECTORY, "error.html") return { "status": 500, "message": "Error whilst parsing uploaded file - please contact Firq on Fate/Sacc Order" }, 406
return returndata return returndata
@blp.route("/", methods=["GET"])
def file_dialog():
return send_from_directory(APISettings.PAGES_DIRECTORY, "index.html")