Guess Post attachment mimetype when 'mediaType' field not provided (#360)

pull/359/head
Michael Manfre 2023-01-05 21:48:03 -05:00 zatwierdzone przez GitHub
rodzic f1fa4aa1e2
commit af47e9dfd6
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 7 dodań i 1 usunięć

Wyświetl plik

@ -1,4 +1,5 @@
import hashlib
import mimetypes
import re
from collections.abc import Iterable
from typing import Optional
@ -795,9 +796,14 @@ class Post(StatorModel):
focal_x, focal_y = attachment["focalPoint"]
else:
focal_x, focal_y = None, None
mimetype = attachment.get("mediaType")
if not mimetype:
mimetype, _ = mimetypes.guess_type(attachment["url"])
if not mimetype:
mimetype = "application/octet-stream"
post.attachments.create(
remote_url=attachment["url"],
mimetype=attachment["mediaType"],
mimetype=mimetype,
name=attachment.get("name"),
width=attachment.get("width"),
height=attachment.get("height"),