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-2022 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 rest_framework.request import Request | |||||
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 | ||||
@api_route( | @api_route( | ||||
r"/snapshot/(?P<snapshot_id>[0-9a-f]+)/", | r"/snapshot/(?P<snapshot_id>[0-9a-f]+)/", | ||||
"api-1-snapshot", | "api-1-snapshot", | ||||
checksum_args=["snapshot_id"], | checksum_args=["snapshot_id"], | ||||
) | ) | ||||
@api_doc("/snapshot/") | @api_doc("/snapshot/") | ||||
@format_docstring() | @format_docstring() | ||||
def api_snapshot(request, snapshot_id): | def api_snapshot(request: Request, snapshot_id: str): | ||||
""" | """ | ||||
.. http:get:: /api/1/snapshot/(snapshot_id)/ | .. http:get:: /api/1/snapshot/(snapshot_id)/ | ||||
Get information about a snapshot in the archive. | Get information about a snapshot in the archive. | ||||
A snapshot is a set of named branches, which are pointers to objects | A snapshot is a set of named branches, which are pointers to objects | ||||
at any level of the Software Heritage DAG. It represents a full picture | at any level of the Software Heritage DAG. It represents a full picture | ||||
of an origin at a given time. | of an origin at a given time. | ||||
Show All 36 Lines | .. http:get:: /api/1/snapshot/(snapshot_id)/ | ||||
:swh_web_api:`snapshot/6a3a2cf0b2b90ce7ae1cf0a221ed68035b686f5a/` | :swh_web_api:`snapshot/6a3a2cf0b2b90ce7ae1cf0a221ed68035b686f5a/` | ||||
""" | """ | ||||
snapshot_content_max_size = get_config()["snapshot_content_max_size"] | snapshot_content_max_size = get_config()["snapshot_content_max_size"] | ||||
branches_from = request.GET.get("branches_from", "") | branches_from = request.GET.get("branches_from", "") | ||||
branches_count = int(request.GET.get("branches_count", snapshot_content_max_size)) | branches_count = int(request.GET.get("branches_count", snapshot_content_max_size)) | ||||
target_types = request.GET.get("target_types", None) | target_types_str = request.GET.get("target_types", None) | ||||
target_types = target_types.split(",") if target_types else None | target_types = target_types_str.split(",") if target_types_str else None | ||||
results = api_lookup( | results = api_lookup( | ||||
archive.lookup_snapshot, | archive.lookup_snapshot, | ||||
snapshot_id, | snapshot_id, | ||||
branches_from, | branches_from, | ||||
branches_count, | branches_count, | ||||
target_types, | target_types, | ||||
branch_name_exclude_prefix=None, | branch_name_exclude_prefix=None, | ||||
Show All 20 Lines |