Support BMP format uploads
This commit is contained in:
parent
ca77149597
commit
a2b68925ac
|
@ -36,6 +36,7 @@
|
||||||
'image/jpeg': 'JPEG',
|
'image/jpeg': 'JPEG',
|
||||||
'image/png': 'PNG',
|
'image/png': 'PNG',
|
||||||
'image/webp': 'WEBP',
|
'image/webp': 'WEBP',
|
||||||
|
'image/bmp': 'BMP',
|
||||||
'video/webm': 'WEBM',
|
'video/webm': 'WEBM',
|
||||||
'video/mp4': 'MPEG-4',
|
'video/mp4': 'MPEG-4',
|
||||||
'application/x-shockwave-flash': 'SWF',
|
'application/x-shockwave-flash': 'SWF',
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
'image/jpeg': 'JPEG',
|
'image/jpeg': 'JPEG',
|
||||||
'image/png': 'PNG',
|
'image/png': 'PNG',
|
||||||
'image/webp': 'WEBP',
|
'image/webp': 'WEBP',
|
||||||
|
'image/bmp': 'BMP',
|
||||||
'video/webm': 'WEBM',
|
'video/webm': 'WEBM',
|
||||||
'video/mp4': 'MPEG-4',
|
'video/mp4': 'MPEG-4',
|
||||||
'application/x-shockwave-flash': 'SWF',
|
'application/x-shockwave-flash': 'SWF',
|
||||||
|
|
|
@ -15,6 +15,7 @@ function _mimeTypeToPostType(mimeType) {
|
||||||
"image/jpeg": "image",
|
"image/jpeg": "image",
|
||||||
"image/png": "image",
|
"image/png": "image",
|
||||||
"image/webp": "image",
|
"image/webp": "image",
|
||||||
|
"image/bmp": "image",
|
||||||
"video/mp4": "video",
|
"video/mp4": "video",
|
||||||
"video/webm": "video",
|
"video/webm": "video",
|
||||||
}[mimeType] || "unknown"
|
}[mimeType] || "unknown"
|
||||||
|
@ -109,6 +110,7 @@ class Url extends Uploadable {
|
||||||
png: "image/png",
|
png: "image/png",
|
||||||
gif: "image/gif",
|
gif: "image/gif",
|
||||||
webp: "image/webp",
|
webp: "image/webp",
|
||||||
|
bmp: "image/bmp",
|
||||||
mp4: "video/mp4",
|
mp4: "video/mp4",
|
||||||
webm: "video/webm",
|
webm: "video/webm",
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,6 +21,9 @@ def get_mime_type(content: bytes) -> str:
|
||||||
if content[8:12] == b"WEBP":
|
if content[8:12] == b"WEBP":
|
||||||
return "image/webp"
|
return "image/webp"
|
||||||
|
|
||||||
|
if content[0:2] == b"BM":
|
||||||
|
return "image/bmp"
|
||||||
|
|
||||||
if content[0:4] == b"\x1A\x45\xDF\xA3":
|
if content[0:4] == b"\x1A\x45\xDF\xA3":
|
||||||
return "video/webm"
|
return "video/webm"
|
||||||
|
|
||||||
|
@ -37,6 +40,7 @@ def get_extension(mime_type: str) -> Optional[str]:
|
||||||
"image/jpeg": "jpg",
|
"image/jpeg": "jpg",
|
||||||
"image/png": "png",
|
"image/png": "png",
|
||||||
"image/webp": "webp",
|
"image/webp": "webp",
|
||||||
|
"image/bmp": "bmp",
|
||||||
"video/mp4": "mp4",
|
"video/mp4": "mp4",
|
||||||
"video/webm": "webm",
|
"video/webm": "webm",
|
||||||
"application/octet-stream": "dat",
|
"application/octet-stream": "dat",
|
||||||
|
@ -58,6 +62,7 @@ def is_image(mime_type: str) -> bool:
|
||||||
"image/png",
|
"image/png",
|
||||||
"image/gif",
|
"image/gif",
|
||||||
"image/webp",
|
"image/webp",
|
||||||
|
"image/bmp",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
|
@ -13,6 +13,7 @@ from szurubooru.func import mime
|
||||||
("jpeg.jpg", "image/jpeg"),
|
("jpeg.jpg", "image/jpeg"),
|
||||||
("gif.gif", "image/gif"),
|
("gif.gif", "image/gif"),
|
||||||
("webp.webp", "image/webp"),
|
("webp.webp", "image/webp"),
|
||||||
|
("bmp.bmp", "image/bmp"),
|
||||||
("text.txt", "application/octet-stream"),
|
("text.txt", "application/octet-stream"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -34,6 +35,7 @@ def test_get_mime_type_for_empty_file():
|
||||||
("image/jpeg", "jpg"),
|
("image/jpeg", "jpg"),
|
||||||
("image/gif", "gif"),
|
("image/gif", "gif"),
|
||||||
("image/webp", "webp"),
|
("image/webp", "webp"),
|
||||||
|
("image/bmp", "bmp"),
|
||||||
("application/octet-stream", "dat"),
|
("application/octet-stream", "dat"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -75,9 +77,11 @@ def test_is_video(input_mime_type, expected_state):
|
||||||
("image/gif", True),
|
("image/gif", True),
|
||||||
("image/png", True),
|
("image/png", True),
|
||||||
("image/jpeg", True),
|
("image/jpeg", True),
|
||||||
|
("image/bmp", True),
|
||||||
("IMAGE/GIF", True),
|
("IMAGE/GIF", True),
|
||||||
("IMAGE/PNG", True),
|
("IMAGE/PNG", True),
|
||||||
("IMAGE/JPEG", True),
|
("IMAGE/JPEG", True),
|
||||||
|
("IMAGE/BMP", True),
|
||||||
("image/anything_else", False),
|
("image/anything_else", False),
|
||||||
("not an image", False),
|
("not an image", False),
|
||||||
],
|
],
|
||||||
|
|
|
@ -392,6 +392,13 @@ def test_update_post_source_with_too_long_string():
|
||||||
model.Post.TYPE_IMAGE,
|
model.Post.TYPE_IMAGE,
|
||||||
"1_244c8840887984c4.gif",
|
"1_244c8840887984c4.gif",
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
False,
|
||||||
|
"bmp.bmp",
|
||||||
|
"image/bmp",
|
||||||
|
model.Post.TYPE_IMAGE,
|
||||||
|
"1_244c8840887984c4.bmp",
|
||||||
|
),
|
||||||
(
|
(
|
||||||
False,
|
False,
|
||||||
"gif-animated.gif",
|
"gif-animated.gif",
|
||||||
|
|
Loading…
Reference in New Issue