Compare commits
No commits in common. "4c43e6a5c5b2f429cc6d0a7cff7648c5e1fdb813" and "d1fa48cb3b514c0ab00cde23feb302ed764d6766" have entirely different histories.
4c43e6a5c5
...
d1fa48cb3b
2 changed files with 2 additions and 39 deletions
|
@ -3,7 +3,7 @@ from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# Add a URL pattern that captures the file path
|
# Add a URL pattern that captures the file path
|
||||||
path('<folder>/<str:file_hash>', views.serve_content_file, name='serve_content_file'),
|
path('submission/<str:file_hash>', views.serve_submission_file, name='serve_submission_file'),
|
||||||
# Other URL patterns if any
|
# Other URL patterns if any
|
||||||
path('upload/', views.fileUpload, name='file_upload'),
|
path('upload/', views.fileUpload, name='file_upload'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -8,16 +8,9 @@ import os
|
||||||
import blake3
|
import blake3
|
||||||
|
|
||||||
from .forms import UploadFileForm
|
from .forms import UploadFileForm
|
||||||
from .models import User_Banner_Images, User_Profile_Images, Metadata_Files, Submission_File
|
from .models import Submission_File
|
||||||
|
|
||||||
|
|
||||||
MODEL_MAP = {
|
|
||||||
'user_profile': User_Profile_Images,
|
|
||||||
'user_banner': User_Banner_Images,
|
|
||||||
'submission': Submission_File,
|
|
||||||
'metadata': Metadata_Files,
|
|
||||||
}
|
|
||||||
|
|
||||||
def compute_file_hash(file):
|
def compute_file_hash(file):
|
||||||
'''
|
'''
|
||||||
Compute BLAKE3 hash of the file
|
Compute BLAKE3 hash of the file
|
||||||
|
@ -56,36 +49,6 @@ def serve_submission_file(request, file_hash):
|
||||||
return HttpResponse("File not found", status=404)
|
return HttpResponse("File not found", status=404)
|
||||||
|
|
||||||
|
|
||||||
@login_required(login_url="/login/")
|
|
||||||
def serve_content_file(request, folder, file_hash):
|
|
||||||
'''
|
|
||||||
View function to serve content files for download or inline viewing
|
|
||||||
'''
|
|
||||||
|
|
||||||
ModelClass = MODEL_MAP.get(folder)
|
|
||||||
if ModelClass is None:
|
|
||||||
return HttpResponse("Invalid folder", status=404)
|
|
||||||
|
|
||||||
download = request.GET.get('d')
|
|
||||||
|
|
||||||
try:
|
|
||||||
obj_file = get_object_or_404(ModelClass, file_hash=file_hash)
|
|
||||||
file = obj_file.file.file
|
|
||||||
file_name = obj_file.file_name
|
|
||||||
|
|
||||||
response = FileResponse(file)
|
|
||||||
if download == "1":
|
|
||||||
response['Content-Disposition'] = f'attachment; filename="{file_name}"'
|
|
||||||
else:
|
|
||||||
response['Content-Disposition'] = f'inline; filename="{file_name}"'
|
|
||||||
|
|
||||||
return response
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error serving file: {e}")
|
|
||||||
return HttpResponse("File not found", status=404)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required(login_url="/login/")
|
@login_required(login_url="/login/")
|
||||||
def fileUpload(request):
|
def fileUpload(request):
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in a new issue