core (xmpp): use pathlib.Path to complete attachments names, and use name to guess type
This commit is contained in:
parent
1ba18cc1fa
commit
b0c3d4d8ac
1 changed files with 4 additions and 2 deletions
|
|
@ -23,6 +23,7 @@ import uuid
|
|||
import mimetypes
|
||||
from urllib.parse import urlparse, unquote
|
||||
from functools import partial
|
||||
from pathlib import Path
|
||||
import shortuuid
|
||||
from sat.core.i18n import _
|
||||
from sat.core.constants import Const as C
|
||||
|
|
@ -1133,10 +1134,11 @@ class SatMessageProtocol(xmppim.MessageProtocol):
|
|||
"""Complete missing metadata of attachments"""
|
||||
for attachment in data['extra'].get(C.MESS_KEY_ATTACHMENTS, []):
|
||||
if "name" not in attachment:
|
||||
name = unquote(urlparse(attachment['url']).path.rsplit('/', 1)[-1])
|
||||
name = (Path(unquote(urlparse(attachment['url']).path)).name
|
||||
or C.FILE_DEFAULT_NAME)
|
||||
attachment["name"] = name
|
||||
if C.MESS_KEY_MEDIA_TYPE not in attachment:
|
||||
media_type = mimetypes.guess_type(attachment['url'], strict=False)[0]
|
||||
media_type = mimetypes.guess_type(attachment['name'], strict=False)[0]
|
||||
if media_type:
|
||||
attachment[C.MESS_KEY_MEDIA_TYPE] = media_type
|
||||
return data
|
||||
|
|
|
|||
Loading…
Reference in a new issue