"""Logic for Image Location.""" from oto import response from assets import config from assets.constants import error from assets.constants import s3 from assets.models import image_location as image_location_model from assets.models import s3_file def get_image_location(entity_id, image_type, image_format): """Get image location. Gets the location for an image or returns an error result if it does not exist in the s3 bucket. Args: image_type: (String): Type of entity (e.g. "product" or "artist"). image_format: (String): Whether this is for a thumbnail or cover. entity_id (Integer): Unique identifier for the product or artist. Returns: Response: the path for the image. """ filename = image_location_model.get_image_filename( entity_id=entity_id, image_type=image_type, image_format=image_format) file_path = '{bucket}/{filename}'.format( bucket=s3.IMAGE_ASSET_BUCKET, filename=filename) s3_check_result = s3_file.check_s3_file_exists( config.ASSET_STORAGE_BUCKET_NAME, file_path) if not s3_check_result: errors = dict( code=error.ERROR_CODE_NOT_FOUND, message=error.ERROR_IMAGE_NOT_FOUND) return response.Response(errors=errors, status=404) return image_location_model.get_image_location_by_filename(filename)