Skip to content

Commit

Permalink
fix: use same base ALLOWED_FORMATS list as thumbor (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
fdintino authored Jul 8, 2024
1 parent 5e44c0c commit 2b4595b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/thumbor_video_engine/filters/format.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
from thumbor.filters import BaseFilter, filter_method, PHASE_PRE_LOAD
import thumbor.filters.format
from thumbor.utils import logger

from thumbor_video_engine.compat import filter_retval


ALLOWED_FORMATS = [
'png', 'jpeg', 'jpg', 'gif', 'webp', 'webm', 'mp4', 'hevc', 'h264', 'h265', 'vp9']
ALLOWED_FORMATS = list(thumbor.filters.format.ALLOWED_FORMATS) + [
"webm",
"mp4",
"hevc",
"h264",
"h265",
"vp9",
]


class Filter(BaseFilter):
phase = PHASE_PRE_LOAD

@filter_method(BaseFilter.String)
def format(self, format):
logger.debug('Setting format to %s' % format)
logger.debug("Setting format to %s" % format)
if format.lower() not in ALLOWED_FORMATS:
logger.warning('Format not allowed: %s' % format.lower())
logger.warning("Format not allowed: %s" % format.lower())
self.context.request.format = None
else:
logger.debug('Format specified: %s' % format.lower())
logger.debug("Format specified: %s" % format.lower())
self.context.request.format = format.lower()

return filter_retval()

0 comments on commit 2b4595b

Please sign in to comment.