Commit 002574d6 authored by BERJON Matthieu's avatar BERJON Matthieu
Browse files

Update of API download view

I updated the download view and restrict it with the
`JobAuthorizationMixin`. I updated as well the link generated for the
files to download by removing the sha1 in the URL that isn't relevant
anymore. I deleted as well the `api/v1` from the url because the
datastore has no meaning to change location in the future therefore the
numerotation of the API in the url isn't necessary.

I deleted the `sha1file` function that isn't used anymore.

I updated the `` file accordingly.
Signed-off-by: BERJON Matthieu's avatarMatthieu Berjon <>
parent 638c90a4
......@@ -7,6 +7,5 @@ app_name = 'api'
urlpatterns = [
url(r'^jobs$',, name='jobs'),
url(r'^jobs/(\d+)', views.APIJobView.as_view(), name='job'),
url(r'^datastore/(\d+)/(.*)/(.*)',, name='download'),
url(r'^datastore/(\d+)/(.*)/(.*)', views.APIDownloadView, name='download'),
......@@ -20,20 +20,9 @@ DATASTORE = config.env.ALLGO_DATASTORE
BUF_SIZE = 65536
def sha1file(filepath):
sha1 = hashlib.sha1()
with open(filepath, 'rb') as f:
while True:
data =
if not data:
return sha1.hexdigest()
def get_link(jobid, dir, filename, request):
filepath = os.path.join(dir, filename)
return '/'.join((get_base_url(request), "api/v1/datastore", str(jobid), sha1file(filepath), filename))
return '/'.join((get_base_url(request), "datastore", str(jobid), filename))
def job_response(job, request):
......@@ -116,7 +105,9 @@ def jobs(request):
return JsonResponse(job_response(job, request))
class APIDownloadView(JobAuthorizationMixin, View):
def download(request, jobid, digest, filename):
return redirect("/datastore/%s/%s" % (jobid, filename))
def get(self, request, *args, **kwargs):
jobid = args[0]
filename = args[1]
return redirect("/datastore/%s/%s" % (jobid, filename))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment