changeset 3297:91b5ae058c66

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.
author Goffi <goffi@goffi.org>
date Tue, 09 Jun 2020 06:23:01 +0200
parents da443cf946ad
children d0e8b0a3ef9c
files sat/plugins/plugin_comp_file_sharing.py
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_comp_file_sharing.py	Tue Jun 09 06:21:23 2020 +0200
+++ b/sat/plugins/plugin_comp_file_sharing.py	Tue Jun 09 06:23:01 2020 +0200
@@ -192,16 +192,25 @@
         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)