forked from claw/flaskpaste
add MIME signatures: RPM, AVI, WAV (RIFF subtypes)
This commit is contained in:
@@ -84,6 +84,8 @@ MAGIC_SIGNATURES: dict[bytes, str] = {
|
|||||||
b"\x04\x22\x4d\x18": "application/x-lz4",
|
b"\x04\x22\x4d\x18": "application/x-lz4",
|
||||||
b"7z\xbc\xaf\x27\x1c": "application/x-7z-compressed",
|
b"7z\xbc\xaf\x27\x1c": "application/x-7z-compressed",
|
||||||
b"Rar!\x1a\x07": "application/vnd.rar",
|
b"Rar!\x1a\x07": "application/vnd.rar",
|
||||||
|
# Packages
|
||||||
|
b"\xed\xab\xee\xdb": "application/x-rpm",
|
||||||
# Data
|
# Data
|
||||||
b"SQLite format 3\x00": "application/x-sqlite3",
|
b"SQLite format 3\x00": "application/x-sqlite3",
|
||||||
}
|
}
|
||||||
@@ -800,9 +802,16 @@ def detect_mime_type(content: bytes, content_type: str | None = None) -> str:
|
|||||||
prefix = content[:MAX_MAGIC_LEN]
|
prefix = content[:MAX_MAGIC_LEN]
|
||||||
for magic, mime in MAGIC_SIGNATURES.items():
|
for magic, mime in MAGIC_SIGNATURES.items():
|
||||||
if prefix[: len(magic)] == magic:
|
if prefix[: len(magic)] == magic:
|
||||||
# RIFF container: verify WEBP subtype
|
# RIFF container: check subtype at bytes 8-12
|
||||||
if magic == b"RIFF" and len(content) >= 12 and content[8:12] != b"WEBP":
|
if magic == b"RIFF" and len(content) >= 12:
|
||||||
continue
|
subtype = content[8:12]
|
||||||
|
if subtype == b"WEBP":
|
||||||
|
return "image/webp"
|
||||||
|
if subtype == b"AVI ":
|
||||||
|
return "video/x-msvideo"
|
||||||
|
if subtype == b"WAVE":
|
||||||
|
return "audio/wav"
|
||||||
|
continue # Unknown RIFF subtype
|
||||||
return mime
|
return mime
|
||||||
|
|
||||||
# Explicit Content-Type (if specific)
|
# Explicit Content-Type (if specific)
|
||||||
|
|||||||
Reference in New Issue
Block a user