diff sat/plugins/plugin_comp_file_sharing.py @ 3331:b1e9f17fbb5a

comp file sharing: minor core re-organisation
author Goffi <goffi@goffi.org>
date Thu, 13 Aug 2020 23:46:18 +0200
parents 15612c0fb421
children 2ad14b834730
line wrap: on
line diff
--- 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: