Mercurial > hg > index.fcgi > www > www-1
diff cs/cs_flask_app.py @ 131:221d6ea7c6c8
cs: add cs_flask_app files
author | paulo |
---|---|
date | Thu, 20 Jan 2022 00:44:05 -0800 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/cs/cs_flask_app.py Thu Jan 20 00:44:05 2022 -0800 1.3 @@ -0,0 +1,23 @@ 1.4 +import os 1.5 + 1.6 +import flask 1.7 +import google.cloud.storage 1.8 +from html3.html3 import HTML 1.9 + 1.10 +app = flask.Flask(__name__) 1.11 + 1.12 +GCS_CLIENT = google.cloud.storage.Client() 1.13 +GCS_BUCKET = GCS_CLIENT.get_bucket(os.environ.get("GCS_BUCKET")) 1.14 + 1.15 +@app.route("/") 1.16 +def index(): 1.17 + return flask.redirect(flask.url_for("file_serve", filename="index.html")) 1.18 + 1.19 + 1.20 +@app.route("/<filename>") 1.21 +def file_serve(filename): 1.22 + file_blob = GCS_BUCKET.get_blob(f"cs/{filename}") 1.23 + if not file_blob: 1.24 + flask.abort(404) 1.25 + 1.26 + return flask.send_file(file_blob.open("rb"), download_name=filename)