comparison sat/plugins/plugin_comp_file_sharing.py @ 3359:000b6722bd35

plugin XEP-0329: added `FISCreateDir` method: This method is used to create a directory for component file sharing, and optionally set its configuration.
author Goffi <goffi@goffi.org>
date Thu, 17 Sep 2020 16:42:00 +0200
parents 12c427156cac
children e3bdfecaf1b0
comparison
equal deleted inserted replaced
3358:b14e95f7034f 3359:000b6722bd35
389 'component file_sharing', 'http_upload_public_facing_url') 389 'component file_sharing', 'http_upload_public_facing_url')
390 if public_base_url is None: 390 if public_base_url is None:
391 client._file_sharing_base_url = f"https://{client.host}:{self.http_port}" 391 client._file_sharing_base_url = f"https://{client.host}:{self.http_port}"
392 else: 392 else:
393 client._file_sharing_base_url = public_base_url 393 client._file_sharing_base_url = public_base_url
394 client._file_sharing_allowed_hosts = self.host.memory.getConfig(
395 'component file_sharing', 'http_upload_allowed_hosts_list') or [client.host]
396 path = client.file_tmp_dir = os.path.join( 394 path = client.file_tmp_dir = os.path.join(
397 self.host.memory.getConfig("", "local_dir"), 395 self.host.memory.getConfig("", "local_dir"),
398 C.FILES_TMP_DIR, 396 C.FILES_TMP_DIR,
399 regex.pathEscape(client.profile), 397 regex.pathEscape(client.profile),
400 ) 398 )
594 log.error(f"trying to purge an inexisting upload slot ({upload_id})") 592 log.error(f"trying to purge an inexisting upload slot ({upload_id})")
595 593
596 def _onHTTPUpload(self, client, request): 594 def _onHTTPUpload(self, client, request):
597 # filename should be already cleaned, but it's better to double check 595 # filename should be already cleaned, but it's better to double check
598 assert '/' not in request.filename 596 assert '/' not in request.filename
597 # client._file_sharing_allowed_hosts is set in plugin XEP-0329
599 if request.from_.host not in client._file_sharing_allowed_hosts: 598 if request.from_.host not in client._file_sharing_allowed_hosts:
600 raise error.StanzaError("forbidden") 599 raise error.StanzaError("forbidden")
601 600
602 upload_id = shortuuid.ShortUUID().random(length=30) 601 upload_id = shortuuid.ShortUUID().random(length=30)
603 assert '/' not in upload_id 602 assert '/' not in upload_id