diff --git a/client/html/post_merge_side.tpl b/client/html/post_merge_side.tpl index b2c1fc6b..53dd31fa 100644 --- a/client/html/post_merge_side.tpl +++ b/client/html/post_merge_side.tpl @@ -35,6 +35,7 @@ 'image/gif': 'GIF', 'image/jpeg': 'JPEG', 'image/png': 'PNG', + 'image/webp': 'WEBP', 'video/webm': 'WEBM', 'video/mp4': 'MPEG-4', 'application/x-shockwave-flash': 'SWF', diff --git a/client/html/post_readonly_sidebar.tpl b/client/html/post_readonly_sidebar.tpl index c959655c..48372f49 100644 --- a/client/html/post_readonly_sidebar.tpl +++ b/client/html/post_readonly_sidebar.tpl @@ -8,6 +8,7 @@ 'image/gif': 'GIF', 'image/jpeg': 'JPEG', 'image/png': 'PNG', + 'image/webp': 'WEBP', 'video/webm': 'WEBM', 'video/mp4': 'MPEG-4', 'application/x-shockwave-flash': 'SWF', diff --git a/client/js/views/post_upload_view.js b/client/js/views/post_upload_view.js index b4d0c409..3ccf7f35 100644 --- a/client/js/views/post_upload_view.js +++ b/client/js/views/post_upload_view.js @@ -13,6 +13,7 @@ function _mimeTypeToPostType(mimeType) { 'image/gif': 'image', 'image/jpeg': 'image', 'image/png': 'image', + 'image/webp': 'image', 'video/mp4': 'video', 'video/webm': 'video', }[mimeType] || 'unknown'; @@ -113,6 +114,7 @@ class Url extends Uploadable { 'jpg': 'image/jpeg', 'png': 'image/png', 'gif': 'image/gif', + 'webp': 'image/webp', 'mp4': 'video/mp4', 'webm': 'video/webm', }; diff --git a/server/szurubooru/func/mime.py b/server/szurubooru/func/mime.py index c83f744e..8f069a12 100644 --- a/server/szurubooru/func/mime.py +++ b/server/szurubooru/func/mime.py @@ -18,6 +18,9 @@ def get_mime_type(content: bytes) -> str: if content[0:6] in (b'GIF87a', b'GIF89a'): return 'image/gif' + if content[8:12] == b'WEBP': + return 'image/webp' + if content[0:4] == b'\x1A\x45\xDF\xA3': return 'video/webm' @@ -33,6 +36,7 @@ def get_extension(mime_type: str) -> Optional[str]: 'image/gif': 'gif', 'image/jpeg': 'jpg', 'image/png': 'png', + 'image/webp': 'webp', 'video/mp4': 'mp4', 'video/webm': 'webm', 'application/octet-stream': 'dat', @@ -49,7 +53,7 @@ def is_video(mime_type: str) -> bool: def is_image(mime_type: str) -> bool: - return mime_type.lower() in ('image/jpeg', 'image/png', 'image/gif') + return mime_type.lower() in ('image/jpeg', 'image/png', 'image/gif', 'image/webp') def is_animated_gif(content: bytes) -> bool: diff --git a/server/szurubooru/tests/assets/webp.webp b/server/szurubooru/tests/assets/webp.webp new file mode 100644 index 00000000..d116e1e7 Binary files /dev/null and b/server/szurubooru/tests/assets/webp.webp differ diff --git a/server/szurubooru/tests/func/test_mime.py b/server/szurubooru/tests/func/test_mime.py index 4b8dcfaf..821ed20b 100644 --- a/server/szurubooru/tests/func/test_mime.py +++ b/server/szurubooru/tests/func/test_mime.py @@ -9,6 +9,7 @@ from szurubooru.func import mime ('png.png', 'image/png'), ('jpeg.jpg', 'image/jpeg'), ('gif.gif', 'image/gif'), + ('webp.webp', 'image/webp'), ('text.txt', 'application/octet-stream'), ]) def test_get_mime_type(read_asset, input_path, expected_mime_type): @@ -26,6 +27,7 @@ def test_get_mime_type_for_empty_file(): ('image/png', 'png'), ('image/jpeg', 'jpg'), ('image/gif', 'gif'), + ('image/webp', 'webp'), ('application/octet-stream', 'dat'), ]) def test_get_extension(mime_type, expected_extension):