def feed_query( request, hints: T.list(T.dict( id=T.feed_unionid.object, dt_updated=T.datetime.object, )).maxlen(MAX_FEED_COUNT * 10).optional, detail: FeedDetailSchema, ) -> T.dict( total=T.int.optional, size=T.int.optional, feeds=T.list(FeedSchema).maxlen(MAX_FEED_COUNT), deleted_size=T.int.optional, deleted_ids=T.list(T.feed_unionid).maxlen(MAX_FEED_COUNT), ): """Feed query, if user feed count exceed limit, only return limit feeds.""" if hints: # allow hints schema exceed feed count limit, but discard exceeded hints = hints[:MAX_FEED_COUNT] check_unionid(request, [x['id'] for x in hints]) total, feeds, deleted_ids = UnionFeed.query_by_user( user_id=request.user.id, hints=hints, detail=detail) feeds = [x.to_dict() for x in feeds] return dict( total=total, size=len(feeds), feeds=feeds, deleted_size=len(deleted_ids), deleted_ids=deleted_ids, )
def feed_query( request, hints: T.list( T.dict(id=T.feed_unionid.object, dt_updated=T.datetime.object)).optional, detail: FeedDetailSchema, ) -> T.dict( total=T.int.optional, size=T.int.optional, feeds=T.list(FeedSchema).maxlen(5000), deleted_size=T.int.optional, deleted_ids=T.list(T.feed_unionid), ): """Feed query""" if hints: check_unionid(request, [x['id'] for x in hints]) total, feeds, deleted_ids = UnionFeed.query_by_user( user_id=request.user.id, hints=hints, detail=detail) feeds = [x.to_dict() for x in feeds] return dict( total=total, size=len(feeds), feeds=feeds, deleted_size=len(deleted_ids), deleted_ids=deleted_ids, )
def story_query_batch( request, storys: T.list( T.dict( feed_id=T.feed_unionid.object, offset=T.int.min(0), limit=T.int.min(1).max(10).default(1), )), detail: StoryDetailSchema, ) -> StoryResultSchema: feed_union_ids = [x['feed_id'] for x in storys] check_unionid(request, feed_union_ids) story_keys = [] for item in storys: feed_id = item['feed_id'].feed_id offset = item['offset'] for i in range(item['limit']): story_keys.append((feed_id, offset + i)) storys = UnionStory.batch_get_by_feed_offset(story_keys=story_keys, user_id=request.user.id, detail=detail) storys = [x.to_dict() for x in storys] return dict( total=len(storys), size=len(storys), storys=storys, )
def feed_delete_all( request, ids: T.list(T.feed_unionid.object).maxlen(MAX_FEED_COUNT).optional, ) -> T.dict(num_deleted=T.int): check_unionid(request, ids) num_deleted = UnionFeed.delete_all(user_id=request.user.id, ids=ids) return dict(num_deleted=num_deleted)
def feed_set_all_readed( request, ids: T.list(T.feed_unionid.object).maxlen(MAX_FEED_COUNT).optional, ) -> T.dict(num_updated=T.int): check_unionid(request, ids) num_updated = UnionFeed.set_all_readed_by_user(user_id=request.user.id, ids=ids) return dict(num_updated=num_updated)
def feed_set_all_group( request, ids: T.list(T.feed_unionid.object).maxlen(MAX_FEED_COUNT), group: T.str.maxlen(50), ) -> T.dict(num_updated=T.int): check_unionid(request, ids) feed_ids = [x.feed_id for x in ids] num_updated = UnionFeed.set_all_group( user_id=request.user.id, feed_ids=feed_ids, group=group) return dict(num_updated=num_updated)
def feed_query_creation( request, limit: T.int.min(10).max(2000).default(500), detail: FeedDetailSchema ) -> T.dict( total=T.int.min(0), size=T.int.min(0), feed_creations=T.list(FeedCreationSchema).maxlen(2000), ): feed_creations = FeedCreation.query_by_user(request.user.id, limit=limit, detail=detail) feed_creations = [x.to_dict() for x in feed_creations] return dict( total=len(feed_creations), size=len(feed_creations), feed_creations=feed_creations, )
def story_query_recent( request, feed_ids: T.list(T.feed_unionid.object).optional, days: T.int.min(1).max(30).default(14), detail: StoryDetailSchema, ) -> StoryResultSchema: check_unionid(request, feed_ids) storys = UnionStory.query_recent_by_user(user_id=request.user.id, feed_unionids=feed_ids, days=days, detail=detail) storys = [x.to_dict() for x in storys] return dict( total=len(storys), size=len(storys), storys=storys, )
dt_created=T.datetime.object.optional, dt_synced=T.datetime.object.optional, is_watched=T.bool.default(False), dt_watched=T.datetime.object.optional, is_favorited=T.bool.default(False), dt_favorited=T.datetime.object.optional, summary=T.str.optional, content=T.str.optional, image_token=T.str.optional, ).slim StoryResultSchema = T.dict( total=T.int.optional, size=T.int.optional, offset=T.int.optional, storys=T.list(StorySchema).maxlen(5000), ) StoryView = RestRouter() STORY_DETAIL_FEILDS = ['story__summary', 'story__content'] @StoryView.get('story/query') def story_query_by_feed( request, feed_id: T.feed_unionid.object, offset: T.int.min(0).optional, size: T.int.min(1).max(100).default(10), detail: StoryDetailSchema, ) -> StoryResultSchema:
return dict( total=result.total, num_created_feeds=len(result.created_feeds), num_existed_feeds=len(result.existed_feeds), num_feed_creations=len(result.feed_creations), created_feeds=created_feeds, feed_creations=feed_creations, ) FeedImportResultSchema = T.dict( total=T.int.min(0), num_created_feeds=T.int.min(0), num_existed_feeds=T.int.min(0), num_feed_creations=T.int.min(0), created_feeds=T.list(FeedSchema).maxlen(5000), feed_creations=T.list(FeedCreationSchema).maxlen(5000), ) @FeedView.post('feed/opml') def feed_import_opml(request) -> FeedImportResultSchema: """import feeds from OPML file""" return feed_import_file(request) @FeedView.get('feed/opml') @FeedView.get('feed/export/opml') def feed_export_opml(request, download: T.bool.default(False)): """export feeds to OPML file""" total, feeds, __ = UnionFeed.query_by_user(request.user.id)
from rest_framework.authtoken.models import Token from rest_framework.permissions import AllowAny from rest_framework.exceptions import AuthenticationFailed from allauth.socialaccount.models import SocialAccount from rssant_config import CONFIG from rssant_common.hashid import HASH_ID UserSchema = T.dict( id=T.str, username=T.str, has_usable_password=T.bool.optional, avatar_url=T.str.optional, token=T.str.optional, social_accounts=T.list(T.dict( provider=T.str, avatar_url=T.str.optional, )).optional, shopant_enable=T.bool.default(False), ) UserView = RestRouter(permission_classes=[AllowAny]) def serialize_user(user): avatar_url = None social_accounts_info = [] social_accounts = list(SocialAccount.objects.filter(user=user).all()) for acc in social_accounts: if not avatar_url: avatar_url = acc.get_avatar_url() social_accounts_info.append(
return dict( total=result.total, num_created_feeds=len(result.created_feeds), num_existed_feeds=len(result.existed_feeds), num_feed_creations=len(result.feed_creations), created_feeds=created_feeds, feed_creations=feed_creations, ) FeedImportResultSchema = T.dict( total=T.int.min(0), num_created_feeds=T.int.min(0), num_existed_feeds=T.int.min(0), num_feed_creations=T.int.min(0), created_feeds=T.list(FeedSchema).maxlen(MAX_FEED_COUNT), feed_creations=T.list(FeedCreationSchema).maxlen(MAX_FEED_COUNT), ) @FeedView.post('feed/opml') def feed_import_opml(request) -> FeedImportResultSchema: """Deprecated. import feeds from OPML file""" return feed_import_file(request) @FeedView.get('feed/opml') @FeedView.get('feed/export/opml') def feed_export_opml(request, download: T.bool.default(False)): """export feeds to OPML file""" total, user_feeds, __ = UnionFeed.query_by_user(request.user.id)