Support BMP format uploads

This commit is contained in:
Ruin0x11 2021-05-09 01:29:36 -07:00
parent ca77149597
commit a2b68925ac
7 changed files with 20 additions and 0 deletions

View file

@ -36,6 +36,7 @@
'image/jpeg': 'JPEG',
'image/png': 'PNG',
'image/webp': 'WEBP',
'image/bmp': 'BMP',
'video/webm': 'WEBM',
'video/mp4': 'MPEG-4',
'application/x-shockwave-flash': 'SWF',

View file

@ -9,6 +9,7 @@
'image/jpeg': 'JPEG',
'image/png': 'PNG',
'image/webp': 'WEBP',
'image/bmp': 'BMP',
'video/webm': 'WEBM',
'video/mp4': 'MPEG-4',
'application/x-shockwave-flash': 'SWF',

View file

@ -15,6 +15,7 @@ function _mimeTypeToPostType(mimeType) {
"image/jpeg": "image",
"image/png": "image",
"image/webp": "image",
"image/bmp": "image",
"video/mp4": "video",
"video/webm": "video",
}[mimeType] || "unknown"
@ -109,6 +110,7 @@ class Url extends Uploadable {
png: "image/png",
gif: "image/gif",
webp: "image/webp",
bmp: "image/bmp",
mp4: "video/mp4",
webm: "video/webm",
};

View file

@ -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",
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

View file

@ -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),
],

View file

@ -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",