Skip to content

Commit

Permalink
Merge 0add5ab into d67a121
Browse files Browse the repository at this point in the history
  • Loading branch information
gi11es committed Nov 5, 2015
2 parents d67a121 + 0add5ab commit 4ae672b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions thumbor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
Config.define('ALLOW_OLD_URLS', True, 'Indicates if encrypted (old style) URLs should be allowed', 'Security')
Config.define('ENABLE_ETAGS', True, 'Enables automatically generated etags', 'HTTP')
Config.define('MAX_ID_LENGTH', 32, 'Set maximum id length for images when stored', 'Storage')
Config.define('ALLOW_DELETE', False, 'Allow image deletion', 'Storage')

# METRICS OPTIONS
Config.define('STATSD_HOST', None, 'Host to send statsd instrumentation to', 'Metrics')
Expand Down
21 changes: 19 additions & 2 deletions thumbor/handlers/imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,29 @@ def check_image(self, kw):
self._error(400, 'Malformed URL: %s' % url)
return

self.execute_image_operations()

@tornado.web.asynchronous
def get(self, **kw):
self.check_image(kw)
self.execute_image_operations()

@tornado.web.asynchronous
def head(self, **kw):
self.check_image(kw)
self.execute_image_operations()

@tornado.web.asynchronous
@tornado.gen.coroutine
def delete(self, **kw):
# Check if image deleting is allowed
if not self.context.config.ALLOW_DELETE:
self._error(405, 'Unable to delete an image')
return

self.check_image(kw)
exists = yield gen.maybe_future(self.context.modules.storage.exists(self.context.request.image_url))

if exists:
self.context.modules.storage.remove(self.context.request.image_url)
self.set_status(204)
else:
self._error(404, 'Image not found at the given URL')

0 comments on commit 4ae672b

Please sign in to comment.