Store images without file extension

This commit is contained in:
Midgard 2024-11-23 18:45:19 +01:00
parent e14c126b2b
commit c1af0c14e7
Signed by: midgard
GPG key ID: 511C112F1331BBB4

View file

@ -4,7 +4,6 @@ import sys
import os
import re
import json
import mimetypes
import urllib.request
@ -46,12 +45,8 @@ def get_emoji_image(name, emoji_id):
print(f"Downloading {name}", file=sys.stderr, flush=True)
with mm_api_get(f"/v4/emoji/{emoji_id}/image") as upstream_response:
headers = {k.lower(): v for (k, v) in upstream_response.headers.items()}
mime = headers.get("content-type")
if not mime.startswith("image/"):
raise Exception(f"Got response with MIME type {mime}, not an image")
extension = mimetypes.guess_extension(mime)
filepath = f"{destination_dir}/{name}{extension}"
filepath = f"{destination_dir}/{name}"
with open(filepath, "wb") as fh:
chunk = upstream_response.read1()
while chunk != b"":