mirror of
https://github.com/jointakahe/takahe.git
synced 2025-06-07 11:18:48 +00:00
Guess Post attachment mimetype when 'mediaType' field not provided (#360)
This commit is contained in:
parent
f1fa4aa1e2
commit
af47e9dfd6
1 changed files with 7 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import mimetypes
|
||||||
import re
|
import re
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
@ -795,9 +796,14 @@ class Post(StatorModel):
|
||||||
focal_x, focal_y = attachment["focalPoint"]
|
focal_x, focal_y = attachment["focalPoint"]
|
||||||
else:
|
else:
|
||||||
focal_x, focal_y = None, None
|
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(
|
post.attachments.create(
|
||||||
remote_url=attachment["url"],
|
remote_url=attachment["url"],
|
||||||
mimetype=attachment["mediaType"],
|
mimetype=mimetype,
|
||||||
name=attachment.get("name"),
|
name=attachment.get("name"),
|
||||||
width=attachment.get("width"),
|
width=attachment.get("width"),
|
||||||
height=attachment.get("height"),
|
height=attachment.get("height"),
|
||||||
|
|
Loading…
Reference in a new issue