comparison pics3/pics_flask_app.py @ 132:99e4022eae52

pics3: add Dockerfile and requirements.pip
author paulo
date Thu, 20 Jan 2022 01:28:46 -0800
parents d216dd8e63da
children 41a6e2d99f68
comparison
equal deleted inserted replaced
1:a19b95cbe1b4 2:65b08637cfbc
9 9
10 app = flask.Flask(__name__) 10 app = flask.Flask(__name__)
11 11
12 GCS_CLIENT = google.cloud.storage.Client() 12 GCS_CLIENT = google.cloud.storage.Client()
13 GCS_BUCKET = GCS_CLIENT.get_bucket(os.environ.get("GCS_BUCKET")) 13 GCS_BUCKET = GCS_CLIENT.get_bucket(os.environ.get("GCS_BUCKET"))
14 PIN = os.environ.get("PIN")
15
16
17 class PinFailError(Exception):
18 def __str__(self):
19 return "PIN FAIL!"
20
21 class PinSetupError(Exception):
22 def __str__(self):
23 return "PIN SETUP ERROR!"
14 24
15 25
16 class PicsDialect(csv.Dialect): 26 class PicsDialect(csv.Dialect):
17 delimiter = '\t' 27 delimiter = '\t'
18 quoting = csv.QUOTE_NONE 28 quoting = csv.QUOTE_NONE
102 def index(): 112 def index():
103 n = 5 # number of thumbnails to display per dir 113 n = 5 # number of thumbnails to display per dir
104 114
105 (root, header, body) = _get_standard_html_doc("Pictures") 115 (root, header, body) = _get_standard_html_doc("Pictures")
106 header.script('', type="text/javascript", src=flask.url_for("static", filename="lazyload.js")) 116 header.script('', type="text/javascript", src=flask.url_for("static", filename="lazyload.js"))
117
118 if not PIN:
119 raise PinSetupError
120 elif flask.request.cookies.get("lahat") != PIN:
121 raise PinFailError
107 122
108 pics_dirs = [] 123 pics_dirs = []
109 pics_dirs_index_blob = GCS_BUCKET.get_blob("pics/index.tsv") 124 pics_dirs_index_blob = GCS_BUCKET.get_blob("pics/index.tsv")
110 if pics_dirs_index_blob: 125 if pics_dirs_index_blob:
111 pics_dirs_index_strlist = pics_dirs_index_blob.download_as_text().splitlines() 126 pics_dirs_index_strlist = pics_dirs_index_blob.download_as_text().splitlines()