Refuse to generate None links, fall back to '' instead.

This commit is contained in:
Sybren A. Stüvel 2016-05-27 16:32:32 +02:00
parent c13ba86323
commit dd90fafad4

View File

@ -280,22 +280,23 @@ def generate_link(backend, file_path, project_id=None, is_public=False):
if backend == 'gcs': if backend == 'gcs':
storage = GoogleCloudStorageBucket(project_id) storage = GoogleCloudStorageBucket(project_id)
blob = storage.Get(file_path) blob = storage.Get(file_path)
if blob and not is_public: if blob is None:
link = blob['signed_url'] return ''
elif blob and is_public:
link = blob['public_url'] if is_public:
else: return blob['public_url']
link = None return blob['signed_url']
elif backend == 'pillar':
link = url_for('file_storage.index', file_name=file_path, _external=True, if backend == 'pillar':
return url_for('file_storage.index', file_name=file_path, _external=True,
_scheme=current_app.config['SCHEME']) _scheme=current_app.config['SCHEME'])
elif backend == 'cdnsun': if backend == 'cdnsun':
link = hash_file_path(file_path, None) return hash_file_path(file_path, None)
elif backend == 'unittest': if backend == 'unittest':
link = md5(file_path).hexdigest() return md5(file_path).hexdigest()
else:
link = None return ''
return link
def before_returning_file(response): def before_returning_file(response):