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.
This commit is contained in:
Goffi 2020-06-09 06:23:01 +02:00
commit 87298f8a19

View file

@ -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)