comp file sharing: minor core re-organisation

This commit is contained in:
Goffi 2020-08-13 23:46:18 +02:00
commit bfa4bbae9e

View file

@ -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: