Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/common.py
# Copyright (C) 2017-2020 The Software Heritage developers | # Copyright (C) 2017-2021 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 General Public License version 3, or any later version | # License: GNU 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 abc import ABCMeta, abstractmethod | from abc import ABCMeta, abstractmethod | ||||
import datetime | import datetime | ||||
import hashlib | import hashlib | ||||
import json | import json | ||||
▲ Show 20 Lines • Show All 1,000 Lines • ▼ Show 20 Lines | ) -> Union[HttpResponse, FileResponse]: | ||||
self.checks(request, collection_name, deposit) | self.checks(request, collection_name, deposit) | ||||
r = self.process_get(request, collection_name, deposit) | r = self.process_get(request, collection_name, deposit) | ||||
status, content, content_type = r | status, content, content_type = r | ||||
if content_type == "swh/generator": | if content_type == "swh/generator": | ||||
with content as path: | with content as path: | ||||
return FileResponse( | return FileResponse( | ||||
open(path, "rb"), status=status, content_type="application/zip" | open(path, "rb"), status=status, content_type="application/tar" | ||||
) | ) | ||||
if content_type == "application/json": | if content_type == "application/json": | ||||
return HttpResponse( | return HttpResponse( | ||||
json.dumps(content), status=status, content_type=content_type | json.dumps(content), status=status, content_type=content_type | ||||
) | ) | ||||
return HttpResponse(content, status=status, content_type=content_type) | return HttpResponse(content, status=status, content_type=content_type) | ||||
@abstractmethod | @abstractmethod | ||||
▲ Show 20 Lines • Show All 171 Lines • Show Last 20 Lines |