Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/snapshot.py
# Copyright (C) 2018-2019 The Software Heritage developers | # Copyright (C) 2018-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from django.http import HttpResponse | |||||
from swh.model.git_objects import snapshot_git_object | |||||
from swh.model.model import Snapshot | |||||
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.utils import enrich_snapshot | from swh.web.api.utils import enrich_snapshot | ||||
from swh.web.api.views.utils import api_lookup | from swh.web.api.views.utils import api_lookup | ||||
from swh.web.common import archive | from swh.web.common import archive | ||||
from swh.web.common.utils import reverse | from swh.web.common.utils import reverse | ||||
from swh.web.config import get_config | from swh.web.config import get_config | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | if results["next_branch"] is not None: | ||||
"branches_from": results["next_branch"], | "branches_from": results["next_branch"], | ||||
"branches_count": branches_count, | "branches_count": branches_count, | ||||
"target_types": target_types, | "target_types": target_types, | ||||
}, | }, | ||||
request=request, | request=request, | ||||
) | ) | ||||
return response | return response | ||||
@api_route( | |||||
r"/snapshot/(?P<snapshot_id>[0-9a-f]+)/git", | |||||
"api-1-snapshot-git-object", | |||||
checksum_args=["snapshot_id"], | |||||
) | |||||
@api_doc("/snapshot/git") | |||||
@format_docstring() | |||||
def api_snapshot_git_object(request, snapshot_id): | |||||
""" | |||||
.. http:get:: /api/1/snapshot/(snapshot_id)/git | |||||
**Example:** | |||||
.. parsed-literal:: | |||||
:swh_web_api:`snapshot/6a3a2cf0b2b90ce7ae1cf0a221ed68035b686f5a/git` | |||||
""" | |||||
snapshot_content_max_size = get_config()["snapshot_content_max_size"] | |||||
branches_from = request.GET.get("branches_from", "") | |||||
branches_count = int(request.GET.get("branches_count", snapshot_content_max_size)) | |||||
target_types = request.GET.get("target_types", None) | |||||
target_types = target_types.split(",") if target_types else None | |||||
data = api_lookup( | |||||
archive.lookup_snapshot, | |||||
snapshot_id, | |||||
branches_from, | |||||
branches_count, | |||||
target_types, | |||||
branch_name_exclude_prefix=None, | |||||
notfound_msg="Snapshot with id {} not found.".format(snapshot_id), | |||||
enrich_fn=enrich_snapshot, | |||||
request=request, | |||||
) | |||||
snapshot = Snapshot.from_dict(data) | |||||
results = snapshot_git_object(snapshot) | |||||
response = HttpResponse(results, content_type="application/octet-stream") | |||||
response["Content-disposition"] = ( | |||||
"attachment;filename=snapshot_%s_raw" % snapshot_id | |||||
) | |||||
return response | |||||
vlorentz: it shouldn't be neded to enrich it. |
it shouldn't be neded to enrich it.