component file sharing: don't initialise the plugin if not component use it

This commit is contained in:
Goffi 2020-06-01 11:15:16 +02:00
commit ca655f01a8

View file

@ -293,24 +293,34 @@ class FileSharingSite(server.Site):
class FileSharing:
def __init__(self, host):
log.info(_("File Sharing initialization"))
self.host = host
self._f = host.plugins["FILE"]
self._jf = host.plugins["XEP-0234"]
self._h = host.plugins["XEP-0300"]
self._t = host.plugins["XEP-0264"]
host.plugins["XEP-0363"].registerHandler(self._onHTTPUpload)
host.trigger.add("FILE_getDestDir", self._getDestDirTrigger)
host.trigger.add(
self.initialised = False
def init(self):
# we init once on first component connection,
# there is not need to init this plugin if not component use it
# TODO: this plugin should not be loaded at all if no component uses it
# and should be loaded dynamically as soon as a suitable profile is created
if self.initialised:
return
self.initialised = True
log.info(_("File Sharing initialization"))
self._f = self.host.plugins["FILE"]
self._jf = self.host.plugins["XEP-0234"]
self._h = self.host.plugins["XEP-0300"]
self._t = self.host.plugins["XEP-0264"]
self.host.plugins["XEP-0363"].registerHandler(self._onHTTPUpload)
self.host.trigger.add("FILE_getDestDir", self._getDestDirTrigger)
self.host.trigger.add(
"XEP-0234_fileSendingRequest", self._fileSendingRequestTrigger, priority=1000
)
host.trigger.add("XEP-0234_buildFileElement", self._addFileComments)
host.trigger.add("XEP-0234_parseFileElement", self._getFileComments)
host.trigger.add("XEP-0329_compGetFilesFromNode", self._addCommentsData)
self.files_path = host.getLocalPath(None, C.FILES_DIR, profile=False)
self.http_port = host.memory.getConfig(
self.host.trigger.add("XEP-0234_buildFileElement", self._addFileComments)
self.host.trigger.add("XEP-0234_parseFileElement", self._getFileComments)
self.host.trigger.add("XEP-0329_compGetFilesFromNode", self._addCommentsData)
self.files_path = self.host.getLocalPath(None, C.FILES_DIR, profile=False)
self.http_port = self.host.memory.getConfig(
'component file_sharing', 'http_upload_port', 8888)
connection_type = host.memory.getConfig(
connection_type = self.host.memory.getConfig(
'component file_sharing', 'http_upload_connection_type', 'https')
if connection_type not in ('http', 'https'):
raise exceptions.ConfigError(
@ -321,7 +331,7 @@ class FileSharing:
if connection_type == 'http':
reactor.listenTCP(self.http_port, self.server)
else:
options = tls.getOptionsFromConfig(host.memory.config, "component file_sharing")
options = tls.getOptionsFromConfig(self.host.memory.config, "component file_sharing")
tls.TLSOptionsCheck(options)
context_factory = tls.getTLSContextFactory(options)
reactor.listenSSL(self.http_port, self.server, context_factory)
@ -331,6 +341,7 @@ class FileSharing:
return Comments_handler(self)
def profileConnecting(self, client):
self.init()
public_base_url = self.host.memory.getConfig(
'component file_sharing', 'http_upload_public_facing_url')
if public_base_url is None: