Rework with UI in mind
This commit is contained in:
parent
fbdb6f9f5a
commit
27fd95ba1e
4 changed files with 5 additions and 58 deletions
|
@ -1,6 +1,6 @@
|
|||
[project]
|
||||
name = "support_formatter"
|
||||
version = "0.1.0-a.2"
|
||||
version = "0.1.0"
|
||||
requires-python = ">= 3.10"
|
||||
authors = [{name = "Firq", email = "firelp42@gmail.com"}]
|
||||
maintainers = [{name = "Firq", email = "firelp42@gmail.com"}]
|
||||
|
|
|
@ -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>
|
|
@ -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>
|
|
@ -1,7 +1,6 @@
|
|||
import os
|
||||
import pathlib
|
||||
from typing import List
|
||||
from flask import send_from_directory
|
||||
import marshmallow as ma
|
||||
from flask_smorest.fields import Upload
|
||||
from werkzeug.datastructures import FileStorage
|
||||
|
@ -26,7 +25,7 @@ class MultipartFileSchema(ma.Schema):
|
|||
servantdata = Upload()
|
||||
cedata = Upload()
|
||||
|
||||
@blp.route("/", methods=["POST"])
|
||||
@blp.route("/upload", methods=["POST"])
|
||||
@blp.arguments(MultipartFormSchema, location="form")
|
||||
@blp.arguments(MultipartFileSchema, location="files")
|
||||
@blp.response(200)
|
||||
|
@ -39,7 +38,7 @@ def upload_file(form: dict[str, str], files: dict[str, FileStorage]):
|
|||
|
||||
for name, file in files.items():
|
||||
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"
|
||||
file.save(filepath)
|
||||
|
@ -51,7 +50,7 @@ def upload_file(form: dict[str, str], files: dict[str, FileStorage]):
|
|||
filepaths.append(filepath)
|
||||
|
||||
if len(filepaths) == 0:
|
||||
return send_from_directory(APISettings.PAGES_DIRECTORY, "error.html")
|
||||
return { "status": 406, "message": "No files provided" }, 406
|
||||
|
||||
try:
|
||||
for f in filepaths:
|
||||
|
@ -61,10 +60,6 @@ def upload_file(form: dict[str, str], files: dict[str, FileStorage]):
|
|||
except FileTypeInvalidError:
|
||||
for f in filepaths:
|
||||
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
|
||||
|
||||
@blp.route("/", methods=["GET"])
|
||||
def file_dialog():
|
||||
return send_from_directory(APISettings.PAGES_DIRECTORY, "index.html")
|
||||
|
|
Loading…
Reference in a new issue