Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/resolvers/content.py
Show All 13 Lines | |||||
class BaseContentNode(BaseSWHNode): | class BaseContentNode(BaseSWHNode): | ||||
""" | """ | ||||
Base resolver for all the content nodes | Base resolver for all the content nodes | ||||
""" | """ | ||||
def _get_content_by_id(self, content_id): | def _get_content_by_id(self, content_id): | ||||
content = archive.Archive().get_content(content_id) | return (archive.Archive().get_contents([content_id]) or None)[0] | ||||
return content[0] if content else None | |||||
@property | @property | ||||
def checksum(self): | def checksum(self): | ||||
# FIXME, return a Node object | # FIXME, return a Node object | ||||
return {k: v.hex() for (k, v) in self._node.hashes().items()} | return {k: v.hex() for (k, v) in self._node.hashes().items()} | ||||
@property | @property | ||||
def id(self): | def id(self): | ||||
Show All 9 Lines | class ContentNode(BaseContentNode): | ||||
""" | """ | ||||
Node resolver for a content requested directly with its SWHID | Node resolver for a content requested directly with its SWHID | ||||
""" | """ | ||||
def _get_node_data(self): | def _get_node_data(self): | ||||
return self._get_content_by_id(self.kwargs.get("swhid").object_id) | return self._get_content_by_id(self.kwargs.get("swhid").object_id) | ||||
class SearchContentNode(BaseContentNode): | |||||
""" | |||||
Node resolver for a content requested from a search result node | |||||
""" | |||||
class TargetContentNode(BaseContentNode): | class TargetContentNode(BaseContentNode): | ||||
""" | """ | ||||
Node resolver for a content requested from a | Node resolver for a content requested from a | ||||
directory entry or from a release target | directory entry or from a release target | ||||
""" | """ | ||||
obj: Union[DirectoryEntryNode, BaseReleaseNode, SnapshotBranchNode] | obj: Union[DirectoryEntryNode, BaseReleaseNode, SnapshotBranchNode] | ||||
def _get_node_data(self): | def _get_node_data(self): | ||||
content_id = self.obj.target_hash | content_id = self.obj.target_hash | ||||
return self._get_content_by_id(content_id) | return self._get_content_by_id(content_id) |