Mercurial > libervia-backend
diff sat/core/xmpp.py @ 3184:e8ce30798d15
core (xmpp): use pathlib.Path to complete attachments names, and use name to guess type
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 26 Feb 2020 15:54:34 +0100 |
parents | 8565af209234 |
children | adf1aeaa0d37 |
line wrap: on
line diff
--- a/sat/core/xmpp.py Sun Feb 23 17:49:21 2020 +0100 +++ b/sat/core/xmpp.py Wed Feb 26 15:54:34 2020 +0100 @@ -23,6 +23,7 @@ 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 @@ """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