From 87298f8a19066a04c2b2db6e864edbb943561bff Mon Sep 17 00:00:00 2001 From: Goffi Date: Tue, 9 Jun 2020 06:23:01 +0200 Subject: [PATCH] comp file sharing: handle upload with headers: `Xmpp-File-Path` can now be used to specify file path, and `Xmpp-File-No-Http` when file must not be served publicly by HTTP. --- sat/plugins/plugin_comp_file_sharing.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sat/plugins/plugin_comp_file_sharing.py b/sat/plugins/plugin_comp_file_sharing.py index 3577f89a..66c8f4dc 100644 --- a/sat/plugins/plugin_comp_file_sharing.py +++ b/sat/plugins/plugin_comp_file_sharing.py @@ -192,16 +192,25 @@ class HTTPFileServer(resource.Resource): tmp_file_path = Path(request.content.name) request.content = None + # the 2 following headers are not standard, but useful in the context of file + # sharing with HTTP Upload: first one allow uploaded to specify the path + # and second one will disable public exposure of the file through HTTP + path = request.getHeader("Xmpp-File-Path") or "/uploads" + if request.getHeader("Xmpp-File-No-Http") is not None: + public_id = None + else: + public_id = upload_id + file_data = { "name": unquote(upload_request.filename), "mime_type": upload_request.content_type, "size": upload_request.size, - "path": "/uploads" + "path": path } await request.file_sharing.registerReceivedFile( client, upload_request.from_, file_data, tmp_file_path, - public_id=upload_id, + public_id=public_id, ) request.setResponseCode(http.CREATED)