Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/vault.py
Show All 12 Lines | |||||
from swh.web.api.apidoc import api_doc, format_docstring | from swh.web.api.apidoc import api_doc, format_docstring | ||||
from swh.web.api.apiurls import api_route | from swh.web.api.apiurls import api_route | ||||
from swh.web.api.views.utils import api_lookup | from swh.web.api.views.utils import api_lookup | ||||
# XXX: a bit spaghetti. Would be better with class-based views. | # XXX: a bit spaghetti. Would be better with class-based views. | ||||
def _dispatch_cook_progress(request, obj_type, obj_id): | def _dispatch_cook_progress(request, obj_type, obj_id): | ||||
hex_id = hashutil.hash_to_hex(obj_id) | hex_id = hashutil.hash_to_hex(obj_id) | ||||
object_name = obj_type.split("_")[0].title() | object_name = obj_type.split("_")[0] | ||||
if request.method == "GET": | if request.method == "GET": | ||||
return api_lookup( | return api_lookup( | ||||
service.vault_progress, | service.vault_progress, | ||||
obj_type, | obj_type, | ||||
obj_id, | obj_id, | ||||
notfound_msg=("{} '{}' was never requested.".format(object_name, hex_id)), | notfound_msg=( | ||||
"Cooking of {} '{}' was never requested.".format(object_name, hex_id) | |||||
), | |||||
request=request, | request=request, | ||||
) | ) | ||||
elif request.method == "POST": | elif request.method == "POST": | ||||
email = request.POST.get("email", request.GET.get("email", None)) | email = request.POST.get("email", request.GET.get("email", None)) | ||||
return api_lookup( | return api_lookup( | ||||
service.vault_cook, | service.vault_cook, | ||||
obj_type, | obj_type, | ||||
obj_id, | obj_id, | ||||
email, | email, | ||||
notfound_msg=("{} '{}' not found.".format(object_name, hex_id)), | notfound_msg=("{} '{}' not found.".format(object_name.title(), hex_id)), | ||||
request=request, | request=request, | ||||
) | ) | ||||
@api_route( | @api_route( | ||||
r"/vault/directory/(?P<dir_id>[0-9a-f]+)/", | r"/vault/directory/(?P<dir_id>[0-9a-f]+)/", | ||||
"api-1-vault-cook-directory", | "api-1-vault-cook-directory", | ||||
methods=["GET", "POST"], | methods=["GET", "POST"], | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | def api_vault_fetch_directory(request, dir_id): | ||||
""" | """ | ||||
_, obj_id = query.parse_hash_with_algorithms_or_throws( | _, obj_id = query.parse_hash_with_algorithms_or_throws( | ||||
dir_id, ["sha1"], "Only sha1_git is supported." | dir_id, ["sha1"], "Only sha1_git is supported." | ||||
) | ) | ||||
res = api_lookup( | res = api_lookup( | ||||
service.vault_fetch, | service.vault_fetch, | ||||
"directory", | "directory", | ||||
obj_id, | obj_id, | ||||
notfound_msg="Directory with ID '{}' not found.".format(dir_id), | notfound_msg="Cooked archive for directory '{}' not found.".format(dir_id), | ||||
request=request, | request=request, | ||||
) | ) | ||||
fname = "{}.tar.gz".format(dir_id) | fname = "{}.tar.gz".format(dir_id) | ||||
response = HttpResponse(res, content_type="application/gzip") | response = HttpResponse(res, content_type="application/gzip") | ||||
response["Content-disposition"] = "attachment; filename={}".format(fname) | response["Content-disposition"] = "attachment; filename={}".format(fname) | ||||
return response | return response | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | def api_vault_fetch_revision_gitfast(request, rev_id): | ||||
""" | """ | ||||
_, obj_id = query.parse_hash_with_algorithms_or_throws( | _, obj_id = query.parse_hash_with_algorithms_or_throws( | ||||
rev_id, ["sha1"], "Only sha1_git is supported." | rev_id, ["sha1"], "Only sha1_git is supported." | ||||
) | ) | ||||
res = api_lookup( | res = api_lookup( | ||||
service.vault_fetch, | service.vault_fetch, | ||||
"revision_gitfast", | "revision_gitfast", | ||||
obj_id, | obj_id, | ||||
notfound_msg="Revision with ID '{}' not found.".format(rev_id), | notfound_msg="Cooked archive for revision '{}' not found.".format(rev_id), | ||||
request=request, | request=request, | ||||
) | ) | ||||
fname = "{}.gitfast.gz".format(rev_id) | fname = "{}.gitfast.gz".format(rev_id) | ||||
response = HttpResponse(res, content_type="application/gzip") | response = HttpResponse(res, content_type="application/gzip") | ||||
response["Content-disposition"] = "attachment; filename={}".format(fname) | response["Content-disposition"] = "attachment; filename={}".format(fname) | ||||
return response | return response | ||||
Show All 16 Lines |