Skip to content

Commit

Permalink
fixed download button
Browse files Browse the repository at this point in the history
  • Loading branch information
elblogbruno committed Aug 22, 2021
1 parent a6808e9 commit ed28841
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
36 changes: 35 additions & 1 deletion controller/modules/files_utils/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,49 @@
from controller.modules.files_utils import files_utils_blu
from controller.utils.video_editor import VideoEditor
from controller.utils.image_editor import ImageEditor
from config import load_custom_video_folder
import os
from uuid import UUID

def is_valid_uuid(uuid_to_test, version=4):
"""
Check if uuid_to_test is a valid UUID.
Parameters
----------
uuid_to_test : str
version : {1, 2, 3, 4}
Returns
-------
`True` if uuid_to_test is a valid UUID, otherwise `False`.
Examples
--------
>>> is_valid_uuid('c9bf9e57-1685-4c89-bafb-ff5af830be8a')
True
>>> is_valid_uuid('c9bf9e58')
False
"""

try:
uuid_obj = UUID(uuid_to_test, version=version)
except ValueError:
return False
return str(uuid_obj) == uuid_to_test

@files_utils_blu.route('/download_file/<string:travel_id>/<string:filename>', methods=['GET'])
def download_file(travel_id, filename):
print(travel_id, filename)
file = Wanderpi.get_by_id(filename)
file_type = 'images' if file.is_image else 'videos'
abs_file_path = get_travel_folder_path(travel_id=travel_id, file_type=file_type)
#file_path = get_travel_folder_path(travel_id=travel_id, filename_or_file_id=filename, file_type=file_type)
file_path = get_travel_folder_path(travel_id=travel_id, filename_or_file_id=filename, file_type=file_type)

# check if file exists, if it does not, maybe it is a custom video or photo
if not os.path.exists(file_path):
filename = Wanderpi.get_by_id(filename).name

if '.' not in filename:
filename = file.file_path.split('/')[-1]

Expand Down
2 changes: 1 addition & 1 deletion controller/templates/single_video_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ <h4> Edit file location: </h4>
<h5 class="card-title"> {{ file.name }} {{ file.is_360 }}</h5>
<h6 class="card-text"> {{ file.created_date }} {{ file.time_duration }} </h6>
<div class="card-footer text-center bg-transparent border-light" role="group" aria-label="Basic example">
<button id="download_video" type="button" onclick="window.location.href='/uploads/{{file.travel_id}}/{{ file.id }}'" class="btn btn-outline-secondary btn-block btn-responsive"><i class="bi bi-file-arrow-down-fill"></i></button>
<button id="download_video" type="button" onclick="window.location.href='{{ url_for('files_utils.download_file',travel_id=file.travel_id, filename=file.id) }}'" class="btn btn-outline-secondary btn-block btn-responsive"><i class="bi bi-file-arrow-down-fill"></i></button>
<button id="share_video" type="button" class="btn btn-outline-secondary btn-block btn-responsive"><i class="bi bi-share"></i></button>
<button id="delete_file" type="button" onclick="window.location.href='/delete_file/{{ file.id }}'"class="btn btn-outline-secondary btn-block btn-responsive"><i class="bi bi-trash"></i></button>
<button id="edit_video" type="button" data-bs-toggle="modal" data-bs-target="#bulkEditModal" class="btn btn-outline-secondary btn-block btn-responsive"><i class="bi bi-pencil"></i></button>
Expand Down

0 comments on commit ed28841

Please sign in to comment.