From bfa4bbae9e17ef710230fb4a7f8e811e5a8c4dac Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 13 Aug 2020 23:46:18 +0200 Subject: [PATCH] comp file sharing: minor core re-organisation --- sat/plugins/plugin_comp_file_sharing.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sat/plugins/plugin_comp_file_sharing.py b/sat/plugins/plugin_comp_file_sharing.py index fa62c8dc..d881d4fe 100644 --- a/sat/plugins/plugin_comp_file_sharing.py +++ b/sat/plugins/plugin_comp_file_sharing.py @@ -28,11 +28,11 @@ from sat.core.i18n import _ 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 @@ PLUGIN_INFO = { C.PI_DEPENDENCIES: [ "FILE", "FILE_SHARING_MANAGEMENT", - "XEP-0231", "XEP-0234", "XEP-0260", "XEP-0261", @@ -404,6 +403,12 @@ class FileSharing: 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 @@ class FileSharing: ) ) - 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: