예제 #1
0
def story_get_by_offset(
        request,
        feed_unionid: T.feed_unionid.object,
        offset: T.int.min(0).optional,
        detail: StoryDetailSchema,
        set_readed: T.bool.default(False),
) -> StorySchema:
    """Story detail"""
    check_unionid(request, feed_unionid)
    try:
        story = UnionStory.get_by_feed_offset(feed_unionid,
                                              offset,
                                              detail=detail)
    except StoryNotFoundError:
        return Response({"message": "does not exist"}, status=400)
    if set_readed:
        try:
            UnionFeed.set_story_offset(feed_unionid, offset + 1)
        except FeedStoryOffsetError as ex:
            return Response({'message': str(ex)}, status=400)
        except ConcurrentUpdateError as ex:
            LOG.error(f'ConcurrentUpdateError: story set_readed {ex}',
                      exc_info=ex)
    image_token = ImageToken(
        referrer=story.link,
        feed=feed_unionid.feed_id,
        offset=offset,
    ).encode(secret=CONFIG.image_token_secret)
    ret = story.to_dict()
    ret.update(image_token=image_token)
    return ret
예제 #2
0
def story_get_by_offset(
    request,
    feed_unionid: T.feed_unionid.object,
    offset: T.int.min(0).optional,
    detail: StoryDetailSchema,
) -> StorySchema:
    """Story detail"""
    check_unionid(request, feed_unionid)
    try:
        story = UnionStory.get_by_feed_offset(feed_unionid, offset, detail=detail)
    except StoryNotFoundError:
        return Response({"message": "does not exist"}, status=400)
    return story.to_dict()
예제 #3
0
def story_fetch_fulltext(
    request,
    feed_id: T.feed_unionid.object,
    offset: T.int.min(0),
) -> T.dict(
        feed_id=T.feed_unionid,
        offset=T.int.min(0),
        response_status=T.int,
        response_status_name=T.str,
        use_proxy=T.bool.optional,
        accept=T_ACCEPT.optional,
        story=StorySchema.optional,
):
    feed_unionid = feed_id
    check_unionid(request, feed_unionid)
    user_id, feed_id = feed_unionid
    content = dict(feed_id=feed_id, offset=offset)
    expire_at = int(time.time() + 60)
    use_proxy = None
    accept = None
    try:
        result = scheduler.ask('harbor_rss.sync_story_fulltext',
                               content,
                               expire_at=expire_at)
    except _TIMEOUT_ERRORS as ex:
        LOG.error(f'Ask harbor_rss.sync_story_fulltext timeout: {ex}')
        response_status = FeedResponseStatus.CONNECTION_TIMEOUT
    else:
        response_status = result['response_status']
        use_proxy = result['use_proxy']
        accept = result['accept']
    story = None
    if accept != FulltextAcceptStrategy.REJECT.value:
        story = UnionStory.get_by_feed_offset(feed_unionid,
                                              offset,
                                              detail=True)
        story = story.to_dict()
    response_status_name = FeedResponseStatus.name_of(response_status)
    return dict(
        feed_id=feed_unionid,
        offset=offset,
        response_status=response_status,
        response_status_name=response_status_name,
        use_proxy=use_proxy,
        accept=accept,
        story=story,
    )
예제 #4
0
파일: story.py 프로젝트: zuzhi/rssant
def story_get_by_offset(
    request,
    feed_unionid: T.feed_unionid.object,
    offset: T.int.min(0).optional,
    detail: StoryDetailSchema,
) -> StorySchema:
    """Story detail"""
    check_unionid(request, feed_unionid)
    try:
        story = UnionStory.get_by_feed_offset(feed_unionid, offset, detail=detail)
    except StoryNotFoundError:
        return Response({"message": "does not exist"}, status=400)
    image_token = ImageToken(referrer=story.link)\
        .encode(secret=CONFIG.image_token_secret)
    ret = story.to_dict()
    ret.update(image_token=image_token)
    return ret