Commit 2f986a20 authored by zhanglu's avatar zhanglu

几种社区卡片添加

parent a807b8fa
......@@ -39,6 +39,6 @@ async def diary_list_by_ids(ctx: Context, request: DiaryListRequest) -> DiaryLis
user_id = request.user_id
res = (await get_current_rpc_invoker()["diary/simple_diary_list"](
diary_ids=request.diary_ids,
# user_id=user_id,
user_id=user_id,
)).unwrap()
return DiaryFormat(request.version, request.device_id).format_feed_card(res)
......@@ -12,10 +12,6 @@ from .schemas import DiaryList, DiaryInfo
class DiaryFormat(BaseFormat):
def __init__(self, version, device_id):
self.version = version
self.device_id = device_id
def format_feed_card(self, diary_list: List[Dict]) -> DiaryList:
res: List[DiaryInfo] = []
......
......@@ -11,10 +11,6 @@ from .schemas import LiveInfo, LiveList
class LiveFormat(BaseFormat):
def __init__(self, version, device_id):
self.version = version
self.device_id = device_id
@classmethod
def _get_live_gm_url(cls, status, topic_id, channel_id):
"""获取直播相关的gm_url。"""
......
......@@ -36,7 +36,7 @@ async def live_list_by_ids(ctx: Context, request: LiveListRequest) -> LiveList:
user_id = request.user_id
res = (await get_current_rpc_invoker()["mimas/live/get_clannels_url/audience"](
ids=request.live_ids,
# user_id=user_id,
user_id=user_id,
)).unwrap()
return await format_lives(request.version, request.device_id, res)
......
......@@ -5,20 +5,17 @@ from typing import List
from gm_types.gaia import SEARCH_TAB_TYPE
from gm_upload.utils.image_utils import Picture
from card.views.utils.html import gm_decode_html
from card.views.schemas import User, Tag
from card.views.utils.tag import transform_tags
from card.libs.protocol import gm_protocol
from card.views.utils.format import BaseFormat
from .schemas import AnswerList, AnswerInfo
from .schemas import AnswerList, AnswerInfo, QuestionList, QuestionInfo, QuestionImage
from .default_pic import default_pic
class AnswerFormat(BaseFormat):
def __init__(self, version, device_id):
self.version = version
self.device_id = device_id
@classmethod
def deal_with_pic_hex(cls, image):
......@@ -95,3 +92,49 @@ class AnswerFormat(BaseFormat):
res.append(answer)
return AnswerList(answers=res)
class QuestionFormat(AnswerFormat):
"""此处禁止新功能开发"""
def format_feed_card(self, question_list) -> QuestionList:
res: List[QuestionInfo] = []
for item in question_list.values():
question = QuestionInfo(**item)
question.gm_url = gm_protocol.get_question_detail(item["question_id"])
tags = transform_tags(
tags=item["tags"],
tab_type=SEARCH_TAB_TYPE.ALL,
filter_free_tag=True,
tags_v3=[],
)
question.tags = [Tag(**tag) for tag in tags]
_intact_images = item.pop("intact_question_images", [])
header_images = item.pop('header_images', [])
if header_images:
_image = header_images[0]
else:
_image = _intact_images and _intact_images[0] or {}
if _image:
_image["image_url"] = self.revert_image(Picture.get_aspectscale_path(_image.pop("image", "")))
question.images = QuestionImage(**self.deal_with_pic_hex(_image))
video_item = item.get("video_cover_list") and item.get("video_cover_list")[0] or {}
question.video_url = video_item.get("video_url", "")
question.video_pic = video_item.get("video_pic", "")
question.short_video_url = video_item.get("short_video_url", "")
question.images.video_url = question.video_url
question.images.video_pic = question.video_url
question.images.short_video_url = question.video_url
question.content = gm_decode_html(item.pop("row_content", ""))
res.append(question)
return QuestionList(questions=res)
from fastapi_rpcd.all import Context, bind # type: ignore
from fastapi_rpcd.all import get_current_rpc_invoker
from .schemas import AnswerListRequest, AnswerList
from .format import AnswerFormat
from .schemas import AnswerListRequest, AnswerList, QuestionListRequest, QuestionList
from .format import AnswerFormat, QuestionFormat
@bind("card/answer/list_by_ids")
async def diary_list_by_ids(ctx: Context, request: AnswerListRequest) -> AnswerList:
async def answer_list_by_ids(ctx: Context, request: AnswerListRequest) -> AnswerList:
if not request.answer_ids:
return AnswerList(answers=[])
......@@ -14,7 +14,21 @@ async def diary_list_by_ids(ctx: Context, request: AnswerListRequest) -> AnswerL
user_id = request.user_id
res = (await get_current_rpc_invoker()["qa/question_answer/list_by_ids_v3"](
answer_ids=request.answer_ids,
# user_id=user_id,
user_id=user_id,
)).unwrap()
return AnswerFormat(request.version, request.device_id).format_feed_card(res)
@bind("card/question/list_by_ids")
async def question_list_by_ids(ctx: Context, request: QuestionListRequest) -> QuestionList:
"""此处禁止新功能开发,后续会弃用"""
if not request.question_ids:
return QuestionList(questions=[])
res = (await get_current_rpc_invoker()["qa/question/get_data_list_by_ids"](
ids=request.question_ids,
)).unwrap()
return QuestionFormat(request.version, request.device_id).format_feed_card(res)
......@@ -3,7 +3,7 @@ from typing import List, Optional
from fastapi_rpcd.all import Schema
from pydantic import Field
from card.views.schemas import User, Tag, Video
from card.views.schemas import User, UserTypeEnum, UserLevel, Tag, Video
class AnswerListRequest(Schema):
......@@ -20,7 +20,6 @@ class QaImage(Schema):
image_webp: str = Field(..., description="webp图片地址")
height: int = Field(0, description="图片地址")
width: str = Field(0, description="图片地址")
image_url: str = Field(..., description="图片地址")
class AnswerInfo(Schema):
......@@ -29,7 +28,6 @@ class AnswerInfo(Schema):
id: int = Field(..., description="问答ID")
title: str = Field(..., description="问答标题")
content: str = Field(..., description="内容")
service_id: str = Field(None, description="日记关联美购ID")
is_voted: bool = Field(False, description="是否点赞")
vote_num: int = Field(0, description="点赞数")
answer_num: int = Field(0, description="对应问题回答数")
......@@ -45,3 +43,63 @@ class AnswerList(Schema):
"""问答卡片列表信息"""
answers: Optional[List[AnswerInfo]] = Field([], description="问答列表")
class QuestionListRequest(Schema):
question_ids: List[int] = Field([], description="问题ID列表")
version: Optional[str] = Field('', description="app版本")
device_id: Optional[str] = Field('', description="设备ID")
class QuestionImage(Schema):
video_pic: Optional[str] = Field('', description="图片地址")
video_url: Optional[str] = Field('', description="视频地址")
short_video_url: Optional[str] = Field('', description="短视频地址")
image_url: str = Field(..., description="图片地址")
image_webp: str = Field(..., description="webp图片地址")
height: int = Field(0, description="图片地址")
width: str = Field(0, description="图片地址")
class VideoCoverList(Schema):
video_pic: Optional[str] = Field('', description="图片地址")
video_url: Optional[str] = Field('', description="视频地址")
short_video_url: Optional[str] = Field('', description="短视频地址")
height: int = Field(0, description="图片地址")
width: str = Field(0, description="图片地址")
class QuestionInfo(Schema):
"""问答信息"""
id: int = Field(..., description="问题ID")
title: str = Field(..., description="问题标题")
content: str = Field(..., description="内容")
gm_url: str = Field(None, description="跳转协议")
is_voted: bool = Field(False, description="是否点赞")
answer_num: int = Field(0, description="对应问题回答数")
view_num: int = Field(0, description="浏览数")
tags: Optional[List[Tag]] = Field([], description="标签")
images: Optional[QuestionImage] = Field({}, description="图片")
user_id: int = Field(None, description="用户ID")
user_name: str = Field(None, description="用户名")
user_portrait: str = Field(None, description="用户头像") # portrait
membership_level: Optional[str] = Field(None, description="用户名")
user_level: UserLevel = Field(None, description="用户Level相关信息")
# video_cover_list: Optional[VideoCoverList] = Field({}, description="视频")
video_pic: Optional[str] = Field('', description="视频图片地址")
cover_url: Optional[str] = Field('', description="封面地址")
video_url: Optional[str] = Field('', description="视频地址")
short_video_url: Optional[str] = Field('', description="短视频地址")
class QuestionList(Schema):
"""问题卡片列表信息"""
questions: Optional[List[QuestionInfo]] = Field([], description="问题列表")
......@@ -8,10 +8,6 @@ from .schemas import SpecialPoolInfo, SpecialPoolList, VisualPageInfo, VisualPag
class SpecialPoolFormat(BaseFormat):
def __init__(self, version, device_id):
self.version = version
self.device_id = device_id
def format_special_pool(self, info):
special_pool = {
......@@ -39,10 +35,6 @@ class SpecialPoolFormat(BaseFormat):
class VisualPageFormat(BaseFormat):
def __init__(self, version, device_id):
self.version = version
self.device_id = device_id
def format_visual_page(self, info):
visual_page = {
......
from card.views.utils.html import gm_decode_html
import copy
from typing import List
......@@ -7,8 +6,9 @@ from gm_types.mimas import TRACTATE_COVER_TYPE
from gm_upload.utils.image_utils import Picture
from card import settings
from card.views.schemas import User, Tag
from card.views.utils.tag import feed_tag_v3_show_filter, transform_tags
from card.views.schemas import Tag
from card.views.utils.html import gm_decode_html
from card.views.utils.tag import feed_tag_v3_show_filter
from card.libs.protocol import gm_protocol
from card.views.utils.format import BaseFormat
from .schemas import Image, TractateList, TractateInfo
......@@ -16,10 +16,6 @@ from .schemas import Image, TractateList, TractateInfo
class TractateFormat(BaseFormat):
def __init__(self, version, device_id):
self.version = version
self.device_id = device_id
@classmethod
def convert_tags(cls, tags, tag_version):
......
......@@ -6,7 +6,7 @@ from .format import TractateFormat
@bind("card/tractate/list_by_ids")
async def diary_list_by_ids(ctx: Context, request: TractateListRequest) -> TractateList:
async def tractate_list_by_ids(ctx: Context, request: TractateListRequest) -> TractateList:
if not request.tractate_ids:
return TractateList(tractates=[])
......@@ -14,7 +14,7 @@ async def diary_list_by_ids(ctx: Context, request: TractateListRequest) -> Tract
res = (await get_current_rpc_invoker()["mimas/tractate/list_by_ids"](
tractate_ids=request.tractate_ids,
need_special_info=True,
# user_id=user_id,
user_id=user_id,
)).unwrap()
tractates = res.get("tractate_list", [])
......
......@@ -8,6 +8,10 @@ from card import settings
class BaseFormat(object):
def __init__(self, version, device_id):
self.version = version
self.device_id = device_id
@classmethod
def revert_image(cls, image):
"""传入图片地址,返回原图(不带后缀)"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment