mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-06-03 10:50:20 +00:00
Backups: bugfix for downloading extracted archive files
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
9367f9bcaf
commit
d01c36a8f5
@ -24,8 +24,7 @@ from urllib.parse import unquote
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.core.files.base import File
|
||||
from django.http import Http404, HttpResponse
|
||||
from django.http import Http404, FileResponse
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import ugettext as _
|
||||
@ -120,16 +119,16 @@ class DownloadArchiveView(View):
|
||||
label = unquote(label)
|
||||
name = unquote(name)
|
||||
filepath = find_exported_archive(label, name)
|
||||
(content_type, encoding) = mimetypes.guess_type(name)
|
||||
with open(filepath, 'rb') as file_handle:
|
||||
response = HttpResponse(File(file_handle),
|
||||
content_type=content_type)
|
||||
content_disposition = 'attachment; filename="%s"' % name
|
||||
response['Content-Disposition'] = content_disposition
|
||||
if encoding:
|
||||
response['Content-Encoding'] = encoding
|
||||
return _get_file_response(filepath, name)
|
||||
|
||||
return response
|
||||
|
||||
def _get_file_response(path, filename):
|
||||
"""Read and return a downloadable file"""
|
||||
(content_type, encoding) = mimetypes.guess_type(filename)
|
||||
response = FileResponse(open(path, 'rb'), content_type=content_type)
|
||||
content_disposition = 'attachment; filename="%s"' % filename
|
||||
response['Content-Disposition'] = content_disposition
|
||||
return response
|
||||
|
||||
|
||||
class UploadArchiveView(SuccessMessageMixin, FormView):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user