in src/gcf/main.py [0:0]
def handle_bucket(request: Request):
"""Decode request and dispatch handling to the functions.
Used by the demo UI to display images and annotation results
from batch processing in the GCS buckets.
Args:
request: Flask HTTP request.aborter
Returns:
HTTP response.
"""
# define return values for invalid request"
result = "Undefined request: [%s]." % request.args
error_code = 404
# get bucket names from env. variables
imagess_bucket = os.environ.get(INPUT_BUCKET_ENV)
if imagess_bucket is None:
logging.error("%s is not defined.", INPUT_BUCKET_ENV)
return make_response("%s is not defined" % INPUT_BUCKET_ENV, 404)
annotations_bucket = os.environ.get(ANNOTATIONS_BUCKET_ENV)
if annotations_bucket is None:
logging.error("%s is not defined.", ANNOTATIONS_BUCKET_ENV)
return make_response("%s is not defined" % ANNOTATIONS_BUCKET_ENV, 404)
result = "Not supported"
error_code = 501
# parse URL path
path_items = request.path.split("?") # separate args
path_items = path_items[0].split("/")
if len(path_items) < 3:
return make_response(result, error_code)
if path_items[2].lower() == "list":
return get_list_of_files(
imagess_bucket,
annotations_bucket,
request.args.get("start"),
request.args.get("end"),
request.args.get("embed"),
)
elif path_items[2].lower() == "imagedata" and len(path_items) > 3:
name = path_items[3]
if name:
image_name = parse.unquote(name)
return get_image(imagess_bucket, image_name)
elif path_items[2].lower() == "annotation" and len(path_items) > 3:
name = path_items[3]
if name:
annotation_name = parse.unquote(name)
return get_annotation(annotations_bucket, annotation_name)
return make_response(result, error_code)