add webp support for uploadable images

This commit is contained in:
Jakob Ketterl
2021-05-07 16:57:54 +02:00
parent 7fc7fe5e82
commit ad8877f83c
4 changed files with 21 additions and 9 deletions

View File

@@ -36,6 +36,9 @@ class ImageUploadController(AuthorizationMixin, AssetsController):
def _is_jpg(self, contents):
return contents[0:3] == bytes([0xFF, 0xD8, 0xFF])
def _is_webp(self, contents):
return contents[0:4] == bytes([0x52, 0x49, 0x46, 0x46]) and contents[8:12] == bytes([0x57, 0x45, 0x42, 0x50])
def processImage(self):
if "id" not in self.request.query:
self.send_json_response({"error": "missing id"}, code=400)
@@ -55,8 +58,10 @@ class ImageUploadController(AuthorizationMixin, AssetsController):
filetype = None
if self._is_png(contents):
filetype = "png"
if self._is_jpg(contents):
elif self._is_jpg(contents):
filetype = "jpg"
elif self._is_webp(contents):
filetype = "webp"
if filetype is None:
self.send_json_response({"error": "unsupported file type"}, code=400)
return