diff options
| -rw-r--r-- | Dockerfile | 2 | ||||
| -rw-r--r-- | hayai/__init__.py | 103 |
2 files changed, 105 insertions, 0 deletions
@@ -6,6 +6,8 @@ COPY requirements.txt requirements.txt RUN pip3 install -r requirements.txt +RUN pip3 install epr-reader + COPY . . EXPOSE 5000 diff --git a/hayai/__init__.py b/hayai/__init__.py index 71868a1..0cc076a 100644 --- a/hayai/__init__.py +++ b/hayai/__init__.py @@ -3,6 +3,7 @@ import os from werkzeug.utils import secure_filename from flask import send_from_directory import shutil +import subprocess app = Flask(__name__) @@ -84,6 +85,108 @@ def upload_file(): <br> + <a href="/reader">Need to reed?</a> + + <br> + <br> + + <hr> + + This project is licensed with the <a href="https://github.com/Fuwn/hayai/blob/main/LICENSE">GNU General Public License v3.0</a>. + </body> +</html> +""" + + [email protected]("/reader", methods=["GET", "POST"]) +def reader(): + # Clean old EPUBs + if os.path.exists("./uploads"): + shutil.rmtree("uploads") + + os.makedirs("./uploads") + + if request.method == "POST": + if "file" not in request.files: + flash("no file part") + + return redirect(request.url) + + file = request.files["file"] + + if file.filename == "": + flash("no selected file") + + return redirect(request.url) + + if file and allowed_file(file.filename): + filename = secure_filename(str(file.filename)) + + file.save(os.path.join("./uploads", filename)) + + output = ( + subprocess.run( + ["epr", "-d", f"./uploads/{filename}"], stdout=subprocess.PIPE + ) + .stdout.decode("utf-8") + .replace("\n\n\n", "\n") + .replace("\n", "<br>") + ) + + return f""" + <!DOCTYPE html> + <html> + <head> + <title>はやい</title> + + <link rel="stylesheet" type="text/css" href="https://latex.now.sh/style.css"> + <link rel="stylesheet" type="text/css" href="https://skybox.sh/css/palettes/base16-light.css"> + <link rel="stylesheet" type="text/css" href="https://skybox.sh/css/risotto.css"> + <link rel="stylesheet" type="text/css" href="https://skybox.sh/css/custom.css"> + </head> + + <body style="max-width: 120ch"> + <style>text-align: center</style> + + <h1>はやい</h1> + + {output} + + <br> + + <hr> + + This project is licensed with the <a href="https://github.com/Fuwn/hayai/blob/main/LICENSE">GNU General Public License v3.0</a>. + </body> + </html> + """ + + return """ +<!DOCTYPE html> +<html> + <head> + <title>はやい</title> + + <link rel="stylesheet" type="text/css" href="https://latex.now.sh/style.css"> + <link rel="stylesheet" type="text/css" href="https://skybox.sh/css/palettes/base16-light.css"> + <link rel="stylesheet" type="text/css" href="https://skybox.sh/css/risotto.css"> + <link rel="stylesheet" type="text/css" href="https://skybox.sh/css/custom.css"> + </head> + + <body> + <style>text-align: center;</style> + + <h1>はやい</h1> + + <blockquote>Upload an EPUB, read it in plain-text.</blockquote> + + <form method=post enctype=multipart/form-data> + <input type="file" name="file"> + <input type="submit" value="アップロード"> + </form> + + <br> + <hr> This project is licensed with the <a href="https://github.com/Fuwn/hayai/blob/main/LICENSE">GNU General Public License v3.0</a>. |