Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gif support #3

Merged
merged 6 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions prism/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,32 @@ def dispatch_request(self, request):
except HTTPException as e:
return e

def get_customer(self, request):
subdomain = request.args.get('customer', None)
if subdomain is None:
subdomain = request.host.split('.' + settings.DOMAIN)[0]
with sentry_sdk.configure_scope() as scope:
scope.set_tag("customer", subdomain)
customer = self.credentials_store.get_customer(subdomain)
return customer

def main(self, request):
path = request.path[1:]
_, extension = os.path.splitext(path.lower())
if extension not in ('.png', '.jpg', '.jpeg'):
if extension not in ('.png', '.jpg', '.jpeg', '.gif'):
raise NotFound()
try:
args = parse_args(path, request)
except Exception as e:
raise BadRequest(e)
subdomain = request.args.get('customer', None)
if subdomain is None:
subdomain = request.host.split('.' + settings.DOMAIN)[0]
with sentry_sdk.configure_scope() as scope:
scope.set_tag("customer", subdomain)
customer = self.credentials_store.get_customer(subdomain)

customer = self.get_customer(request)
if extension == '.gif' and request.args.get('out', 'gif') == 'gif':
s3_url = core.get_s3_url(customer.read_bucket_name, customer.read_bucket_region, path)
if core.check_s3_object_exists(s3_url):
return redirect(s3_url)
raise NotFound()

if args['command'] == 'info':
return info(path, args, customer)
else:
Expand All @@ -79,7 +90,7 @@ def not_found(self, request):
raise NotFound()

def test(self, request):
return Response(open('static/test.html'), content_type='text/html')
return Response(open('prism/static/test.html'), content_type='text/html')

def elb_health_check(self, request):
# If HTTPError occurs or can't find the given image gives Response as 500
Expand Down Expand Up @@ -355,7 +366,7 @@ def clear_old_tmp_files():
if os.stat(tmp_file).st_mtime < now - 300:
os.remove(tmp_file)
except Exception:
# An error might occur if the file has aready been deleted by another proceess. We don't care.
# An error might occur if the file has already been deleted by another process. We don't care.
pass


Expand Down
14 changes: 13 additions & 1 deletion prism/static/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@
});
})
li.append('p').text(function(d){ return d});

var ul = d3.select('#container')
var li = ul.append('li')
var gif_image = '/images/baby_hipo.gif'
origins.forEach(function(origin){
li.append('img').attr('src', function(){
return origin + gif_image + '?' + cmds[0];
});
})
li.append('p').text(function(d){ return gif_image + '?' + cmds[0]});


</script>
</body>
</html>
</html>