Mercurial > libervia-backend
comparison sat/plugins/plugin_comp_file_sharing.py @ 3291:449dfbfcdbcc
component file sharing: don't initialise the plugin if not component use it
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 01 Jun 2020 11:15:16 +0200 |
parents | 9057713ab124 |
children | da443cf946ad |
comparison
equal
deleted
inserted
replaced
3290:3ff952c042ae | 3291:449dfbfcdbcc |
---|---|
291 | 291 |
292 | 292 |
293 class FileSharing: | 293 class FileSharing: |
294 | 294 |
295 def __init__(self, host): | 295 def __init__(self, host): |
296 self.host = host | |
297 self.initialised = False | |
298 | |
299 def init(self): | |
300 # we init once on first component connection, | |
301 # there is not need to init this plugin if not component use it | |
302 # TODO: this plugin should not be loaded at all if no component uses it | |
303 # and should be loaded dynamically as soon as a suitable profile is created | |
304 if self.initialised: | |
305 return | |
306 self.initialised = True | |
296 log.info(_("File Sharing initialization")) | 307 log.info(_("File Sharing initialization")) |
297 self.host = host | 308 self._f = self.host.plugins["FILE"] |
298 self._f = host.plugins["FILE"] | 309 self._jf = self.host.plugins["XEP-0234"] |
299 self._jf = host.plugins["XEP-0234"] | 310 self._h = self.host.plugins["XEP-0300"] |
300 self._h = host.plugins["XEP-0300"] | 311 self._t = self.host.plugins["XEP-0264"] |
301 self._t = host.plugins["XEP-0264"] | 312 self.host.plugins["XEP-0363"].registerHandler(self._onHTTPUpload) |
302 host.plugins["XEP-0363"].registerHandler(self._onHTTPUpload) | 313 self.host.trigger.add("FILE_getDestDir", self._getDestDirTrigger) |
303 host.trigger.add("FILE_getDestDir", self._getDestDirTrigger) | 314 self.host.trigger.add( |
304 host.trigger.add( | |
305 "XEP-0234_fileSendingRequest", self._fileSendingRequestTrigger, priority=1000 | 315 "XEP-0234_fileSendingRequest", self._fileSendingRequestTrigger, priority=1000 |
306 ) | 316 ) |
307 host.trigger.add("XEP-0234_buildFileElement", self._addFileComments) | 317 self.host.trigger.add("XEP-0234_buildFileElement", self._addFileComments) |
308 host.trigger.add("XEP-0234_parseFileElement", self._getFileComments) | 318 self.host.trigger.add("XEP-0234_parseFileElement", self._getFileComments) |
309 host.trigger.add("XEP-0329_compGetFilesFromNode", self._addCommentsData) | 319 self.host.trigger.add("XEP-0329_compGetFilesFromNode", self._addCommentsData) |
310 self.files_path = host.getLocalPath(None, C.FILES_DIR, profile=False) | 320 self.files_path = self.host.getLocalPath(None, C.FILES_DIR, profile=False) |
311 self.http_port = host.memory.getConfig( | 321 self.http_port = self.host.memory.getConfig( |
312 'component file_sharing', 'http_upload_port', 8888) | 322 'component file_sharing', 'http_upload_port', 8888) |
313 connection_type = host.memory.getConfig( | 323 connection_type = self.host.memory.getConfig( |
314 'component file_sharing', 'http_upload_connection_type', 'https') | 324 'component file_sharing', 'http_upload_connection_type', 'https') |
315 if connection_type not in ('http', 'https'): | 325 if connection_type not in ('http', 'https'): |
316 raise exceptions.ConfigError( | 326 raise exceptions.ConfigError( |
317 f'bad http_upload_connection_type, you must use one of "http" or "https"' | 327 f'bad http_upload_connection_type, you must use one of "http" or "https"' |
318 ) | 328 ) |
319 self.server = FileSharingSite(self) | 329 self.server = FileSharingSite(self) |
320 self.expected_uploads = {} | 330 self.expected_uploads = {} |
321 if connection_type == 'http': | 331 if connection_type == 'http': |
322 reactor.listenTCP(self.http_port, self.server) | 332 reactor.listenTCP(self.http_port, self.server) |
323 else: | 333 else: |
324 options = tls.getOptionsFromConfig(host.memory.config, "component file_sharing") | 334 options = tls.getOptionsFromConfig(self.host.memory.config, "component file_sharing") |
325 tls.TLSOptionsCheck(options) | 335 tls.TLSOptionsCheck(options) |
326 context_factory = tls.getTLSContextFactory(options) | 336 context_factory = tls.getTLSContextFactory(options) |
327 reactor.listenSSL(self.http_port, self.server, context_factory) | 337 reactor.listenSSL(self.http_port, self.server, context_factory) |
328 | 338 |
329 | 339 |
330 def getHandler(self, client): | 340 def getHandler(self, client): |
331 return Comments_handler(self) | 341 return Comments_handler(self) |
332 | 342 |
333 def profileConnecting(self, client): | 343 def profileConnecting(self, client): |
344 self.init() | |
334 public_base_url = self.host.memory.getConfig( | 345 public_base_url = self.host.memory.getConfig( |
335 'component file_sharing', 'http_upload_public_facing_url') | 346 'component file_sharing', 'http_upload_public_facing_url') |
336 if public_base_url is None: | 347 if public_base_url is None: |
337 client._file_sharing_base_url = f"https://{client.host}:{self.http_port}" | 348 client._file_sharing_base_url = f"https://{client.host}:{self.http_port}" |
338 else: | 349 else: |