From cc64b41fffde7d27eac796cba3f85f071658d581 Mon Sep 17 00:00:00 2001 From: Martijn de Vos Date: Tue, 12 Oct 2021 11:26:41 +0200 Subject: [PATCH] Fixed Marshmallow REST schemas Fixes #6420 --- .../restapi/channels_endpoint.py | 12 +++---- .../metadata_store/restapi/metadata_schema.py | 35 +++++++------------ 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/src/tribler-core/tribler_core/components/metadata_store/restapi/channels_endpoint.py b/src/tribler-core/tribler_core/components/metadata_store/restapi/channels_endpoint.py index 3c428f37e82..be9301762da 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/restapi/channels_endpoint.py +++ b/src/tribler-core/tribler_core/components/metadata_store/restapi/channels_endpoint.py @@ -20,7 +20,7 @@ from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.metadata_store.db.orm_bindings.channel_node import DIRTY_STATUSES, NEW from tribler_core.components.metadata_store.restapi.metadata_endpoint_base import MetadataEndpointBase -from tribler_core.components.metadata_store.restapi.metadata_schema import ChannelSchema +from tribler_core.components.metadata_store.restapi.metadata_schema import ChannelSchema, MetadataSchema, TorrentSchema from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT, REGULAR_TORRENT from tribler_core.components.metadata_store.utils import NoChannelSourcesException, RequestTimeoutException from tribler_core.restapi.rest_endpoint import HTTP_BAD_REQUEST, HTTP_NOT_FOUND, RESTResponse @@ -150,7 +150,7 @@ async def get_channels(self, request): 200: { 'schema': schema( GetChannelContentsResponse={ - 'results': [Dict()], + 'results': [MetadataSchema], 'first': Integer(), 'last': Integer(), 'sort_by': String(), @@ -306,7 +306,7 @@ async def copy_channel(self, request): responses={ 200: { 'description': 'Returns the newly created channel', - 'schema': schema(CreateChannelResponse={'results': [Dict()]}), + 'schema': schema(CreateChannelResponse={'results': [ChannelSchema]}), } }, ) @@ -324,7 +324,7 @@ async def create_channel(self, request): responses={ 200: { 'description': 'Returns the newly created collection', - 'schema': schema(CreateCollectionResponse={'results': [Dict()]}), + 'schema': schema(CreateCollectionResponse={'results': [ChannelSchema]}), } }, ) @@ -468,8 +468,8 @@ async def is_channel_dirty(self, request): responses={ 200: { 'schema': schema( - GetChannelContentsResponse={ - 'results': [Dict()], + GetPopularTorrentsResponse={ + 'results': [TorrentSchema], 'first': Integer(), 'last': Integer(), } diff --git a/src/tribler-core/tribler_core/components/metadata_store/restapi/metadata_schema.py b/src/tribler-core/tribler_core/components/metadata_store/restapi/metadata_schema.py index b4e928e4e38..71d20ca6cf2 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/restapi/metadata_schema.py +++ b/src/tribler-core/tribler_core/components/metadata_store/restapi/metadata_schema.py @@ -20,45 +20,34 @@ class RemoteQueryParameters(MetadataParameters): channel_pk = String() -class ChannelSchema(Schema): +class MetadataSchema(Schema): type = Integer() id = Integer() origin_id = Integer() public_key = String() name = String() category = String() - status = Integer() + progress = Float(required=False) + + +class CollectionSchema(MetadataSchema): torrents = Integer() state = String() - dirty = Boolean() - infohash = String() - size = Integer() - num_seeders = Integer() - num_leechers = Integer() - last_tracker_check = Integer() - updated = Integer() - subscribed = Boolean() - votes = Float() - progress = Float() + description_flag = Boolean() + thumbnail_flag = Boolean() -class TorrentSchema(Schema): - type = Integer() - id = Integer() - origin_id = Integer() - public_key = String() - name = String() - category = String() +class TorrentSchema(MetadataSchema): status = Integer() - torrents = Integer() - state = String() - dirty = Boolean() infohash = String() size = Integer() num_seeders = Integer() num_leechers = Integer() last_tracker_check = Integer() updated = Integer() + + +class ChannelSchema(TorrentSchema, CollectionSchema): + dirty = Boolean() subscribed = Boolean() votes = Float() - progress = Float()