mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
Support BMP format uploads
This commit is contained in:
@ -21,6 +21,9 @@ def get_mime_type(content: bytes) -> str:
|
||||
if content[8:12] == b"WEBP":
|
||||
return "image/webp"
|
||||
|
||||
if content[0:2] == b"BM":
|
||||
return "image/bmp"
|
||||
|
||||
if content[0:4] == b"\x1A\x45\xDF\xA3":
|
||||
return "video/webm"
|
||||
|
||||
@ -37,6 +40,7 @@ def get_extension(mime_type: str) -> Optional[str]:
|
||||
"image/jpeg": "jpg",
|
||||
"image/png": "png",
|
||||
"image/webp": "webp",
|
||||
"image/bmp": "bmp",
|
||||
"video/mp4": "mp4",
|
||||
"video/webm": "webm",
|
||||
"application/octet-stream": "dat",
|
||||
@ -58,6 +62,7 @@ def is_image(mime_type: str) -> bool:
|
||||
"image/png",
|
||||
"image/gif",
|
||||
"image/webp",
|
||||
"image/bmp",
|
||||
)
|
||||
|
||||
|
||||
|
BIN
server/szurubooru/tests/assets/bmp.bmp
Normal file
BIN
server/szurubooru/tests/assets/bmp.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
@ -13,6 +13,7 @@ from szurubooru.func import mime
|
||||
("jpeg.jpg", "image/jpeg"),
|
||||
("gif.gif", "image/gif"),
|
||||
("webp.webp", "image/webp"),
|
||||
("bmp.bmp", "image/bmp"),
|
||||
("text.txt", "application/octet-stream"),
|
||||
],
|
||||
)
|
||||
@ -34,6 +35,7 @@ def test_get_mime_type_for_empty_file():
|
||||
("image/jpeg", "jpg"),
|
||||
("image/gif", "gif"),
|
||||
("image/webp", "webp"),
|
||||
("image/bmp", "bmp"),
|
||||
("application/octet-stream", "dat"),
|
||||
],
|
||||
)
|
||||
@ -75,9 +77,11 @@ def test_is_video(input_mime_type, expected_state):
|
||||
("image/gif", True),
|
||||
("image/png", True),
|
||||
("image/jpeg", True),
|
||||
("image/bmp", True),
|
||||
("IMAGE/GIF", True),
|
||||
("IMAGE/PNG", True),
|
||||
("IMAGE/JPEG", True),
|
||||
("IMAGE/BMP", True),
|
||||
("image/anything_else", False),
|
||||
("not an image", False),
|
||||
],
|
||||
|
@ -392,6 +392,13 @@ def test_update_post_source_with_too_long_string():
|
||||
model.Post.TYPE_IMAGE,
|
||||
"1_244c8840887984c4.gif",
|
||||
),
|
||||
(
|
||||
False,
|
||||
"bmp.bmp",
|
||||
"image/bmp",
|
||||
model.Post.TYPE_IMAGE,
|
||||
"1_244c8840887984c4.bmp",
|
||||
),
|
||||
(
|
||||
False,
|
||||
"gif-animated.gif",
|
||||
|
Reference in New Issue
Block a user