Mercurial > hg > index.fcgi > www > www-1
annotate cs/cs_flask_app.py @ 132:99e4022eae52
pics3: add Dockerfile and requirements.pip
author | paulo |
---|---|
date | Thu, 20 Jan 2022 01:28:46 -0800 |
parents | |
children |
rev | line source |
---|---|
paulo@131 | 1 import os |
paulo@131 | 2 |
paulo@131 | 3 import flask |
paulo@131 | 4 import google.cloud.storage |
paulo@131 | 5 from html3.html3 import HTML |
paulo@131 | 6 |
paulo@131 | 7 app = flask.Flask(__name__) |
paulo@131 | 8 |
paulo@131 | 9 GCS_CLIENT = google.cloud.storage.Client() |
paulo@131 | 10 GCS_BUCKET = GCS_CLIENT.get_bucket(os.environ.get("GCS_BUCKET")) |
paulo@131 | 11 |
paulo@131 | 12 @app.route("/") |
paulo@131 | 13 def index(): |
paulo@131 | 14 return flask.redirect(flask.url_for("file_serve", filename="index.html")) |
paulo@131 | 15 |
paulo@131 | 16 |
paulo@131 | 17 @app.route("/<filename>") |
paulo@131 | 18 def file_serve(filename): |
paulo@131 | 19 file_blob = GCS_BUCKET.get_blob(f"cs/{filename}") |
paulo@131 | 20 if not file_blob: |
paulo@131 | 21 flask.abort(404) |
paulo@131 | 22 |
paulo@131 | 23 return flask.send_file(file_blob.open("rb"), download_name=filename) |