# HG changeset patch # User Goffi # Date 1597355178 -7200 # Node ID b1e9f17fbb5af600206e557093128da706b8321f # Parent 7b47f48d31f3514a4c5969fa3d757a6a7e9c32e2 comp file sharing: minor core re-organisation diff -r 7b47f48d31f3 -r b1e9f17fbb5a sat/plugins/plugin_comp_file_sharing.py --- a/sat/plugins/plugin_comp_file_sharing.py Thu Aug 13 23:46:18 2020 +0200 +++ b/sat/plugins/plugin_comp_file_sharing.py Thu Aug 13 23:46:18 2020 +0200 @@ -28,11 +28,11 @@ from sat.core.constants import Const as C from sat.core import exceptions from sat.core.log import getLogger +from sat.tools import stream from sat.tools.common import regex from sat.tools.common import uri from sat.tools.common import files_utils from sat.tools.common import tls -from sat.tools import stream from twisted.internet import defer, reactor from twisted.words.protocols.jabber import error from twisted.web import server, resource, static, http @@ -52,7 +52,6 @@ C.PI_DEPENDENCIES: [ "FILE", "FILE_SHARING_MANAGEMENT", - "XEP-0231", "XEP-0234", "XEP-0260", "XEP-0261", @@ -404,6 +403,12 @@ if extra is None: extra = {} + mime_type = file_data.get("mime_type") + if not mime_type or mime_type == "application/octet-stream": + mime_type = mimetypes.guess_type(name)[0] + + is_image = mime_type is not None and mime_type.startswith("image") + if file_data.get("hash_algo") == HASH_ALGO: log.debug(_("Reusing already generated hash")) file_hash = file_data["hash_hasher"].hexdigest() @@ -428,11 +433,8 @@ ) ) - mime_type = file_data.get("mime_type") - if not mime_type or mime_type == "application/octet-stream": - mime_type = mimetypes.guess_type(name)[0] - if mime_type is not None and mime_type.startswith("image"): + if is_image: thumbnails = extra.setdefault(C.KEY_THUMBNAILS, []) for max_thumb_size in self._t.SIZES: try: