Skip to content

Commit

Permalink
fix: file upload with dropzone
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Apr 22, 2024
1 parent 41f9f07 commit ed47181
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
18 changes: 11 additions & 7 deletions web/b3desk/endpoints/meeting_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ def download_meeting_files(meeting: Meeting, owner: User, file_id=None):
def insertDocuments(meeting: Meeting):
from flask import request

files_title = request.get_json()
filenames = request.get_json()
secret_key = current_app.config["SECRET_KEY"]

xml_beg = "<?xml version='1.0' encoding='UTF-8'?> <modules> <module name='presentation'> "
xml_end = " </module></modules>"
xml_mid = ""
# @FIX We ONLY send the documents that have been uploaded NOW, not ALL of them for this meetingid ;)
for cur_file in files_title:
id = add_external_meeting_file_nextcloud(cur_file, meeting.id)
for filename in filenames:
id = add_external_meeting_file_nextcloud(filename, meeting.id)
filehash = hashlib.sha1(
f"{secret_key}-1-{id}-{secret_key}".encode()
).hexdigest()
Expand All @@ -174,9 +174,10 @@ def insertDocuments(meeting: Meeting):
isexternal=1,
mfid=id,
mftoken=filehash,
filename=filename,
_external=True,
)
xml_mid += f"<document url='{url}' filename='{cur_file}' />"
xml_mid += f"<document url='{url}' filename='{filename}' />"

bbb_endpoint = current_app.config["BIGBLUEBUTTON_ENDPOINT"]
xml = xml_beg + xml_mid + xml_end
Expand Down Expand Up @@ -546,6 +547,7 @@ def insertDoc(token):
isexternal=0,
mfid=meeting_file.id,
mftoken=meeting_file.download_hash,
filename=meeting_file.title,
_external=True,
)
xml = f"<?xml version='1.0' encoding='UTF-8'?> <modules> <module name='presentation'><document url='{url}' filename='{meeting_file.title}' /> </module></modules>"
Expand All @@ -561,8 +563,8 @@ def insertDoc(token):


@bp.route("/ncdownload/<int:isexternal>/<mfid>/<mftoken>")
# @auth.token_auth(provider_name="default") - must be accessible by BBB server, so no auth
def ncdownload(isexternal, mfid, mftoken):
@bp.route("/ncdownload/<int:isexternal>/<mfid>/<mftoken>/<filename>")
def ncdownload(isexternal, mfid, mftoken, filename=None):
secret_key = current_app.config["SECRET_KEY"]
# select good file from token
# get file through NC credentials - HOW POSSIBLE ?
Expand Down Expand Up @@ -607,4 +609,6 @@ def ncdownload(isexternal, mfid, mftoken):
return jsonify(status=500, msg="La connexion avec Nextcloud semble rompue")

# send the downloaded file to the BBB:
return send_from_directory(TMP_DOWNLOAD_DIR, uniqfile)
return send_from_directory(
TMP_DOWNLOAD_DIR, uniqfile, download_name=meeting_file.title
)
2 changes: 2 additions & 0 deletions web/b3desk/models/bbb.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ def meeting_file_addition_xml(self, meeting_files):
isexternal=0,
mfid=meeting_file.id,
mftoken=filehash,
filename=meeting_file.title,
_external=True,
_scheme=current_app.config["PREFERRED_URL_SCHEME"],
)
xml_mid += f"<document downloadable='{'true' if meeting_file.is_downloadable else 'false'}' url='{url}' filename='{meeting_file.title}' />"

Expand Down
2 changes: 1 addition & 1 deletion web/tests/meeting/test_meeting.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def test_create_with_files(
== "<?xml version='1.0' encoding='UTF-8'?> "
+ "<modules> "
+ "<module name='presentation'> "
+ f"<document downloadable='false' url='http://localhost:5000/ncdownload/0/1/{filehash}' filename='file_title' /> "
+ f"<document downloadable='false' url='http://localhost:5000/ncdownload/0/1/{filehash}/file_title' filename='file_title' /> "
+ "</module>"
+ "</modules>"
)
Expand Down

0 comments on commit ed47181

Please sign in to comment.