Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
card
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhanglu
card
Commits
2f986a20
Commit
2f986a20
authored
Nov 30, 2020
by
zhanglu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
几种社区卡片添加
parent
a807b8fa
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
138 additions
and
39 deletions
+138
-39
diary.py
card/views/diary/diary.py
+1
-1
format.py
card/views/diary/format.py
+0
-4
format.py
card/views/live/format.py
+0
-4
live.py
card/views/live/live.py
+1
-1
format.py
card/views/qa/format.py
+48
-5
qa.py
card/views/qa/qa.py
+18
-4
schemas.py
card/views/qa/schemas.py
+61
-3
format.py
card/views/special_pool/format.py
+0
-8
format.py
card/views/tractate/format.py
+3
-7
tractate.py
card/views/tractate/tractate.py
+2
-2
format.py
card/views/utils/format.py
+4
-0
No files found.
card/views/diary/diary.py
View file @
2f986a20
...
@@ -39,6 +39,6 @@ async def diary_list_by_ids(ctx: Context, request: DiaryListRequest) -> DiaryLis
...
@@ -39,6 +39,6 @@ async def diary_list_by_ids(ctx: Context, request: DiaryListRequest) -> DiaryLis
user_id
=
request
.
user_id
user_id
=
request
.
user_id
res
=
(
await
get_current_rpc_invoker
()[
"diary/simple_diary_list"
](
res
=
(
await
get_current_rpc_invoker
()[
"diary/simple_diary_list"
](
diary_ids
=
request
.
diary_ids
,
diary_ids
=
request
.
diary_ids
,
#
user_id=user_id,
user_id
=
user_id
,
))
.
unwrap
()
))
.
unwrap
()
return
DiaryFormat
(
request
.
version
,
request
.
device_id
)
.
format_feed_card
(
res
)
return
DiaryFormat
(
request
.
version
,
request
.
device_id
)
.
format_feed_card
(
res
)
card/views/diary/format.py
View file @
2f986a20
...
@@ -12,10 +12,6 @@ from .schemas import DiaryList, DiaryInfo
...
@@ -12,10 +12,6 @@ from .schemas import DiaryList, DiaryInfo
class
DiaryFormat
(
BaseFormat
):
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
:
def
format_feed_card
(
self
,
diary_list
:
List
[
Dict
])
->
DiaryList
:
res
:
List
[
DiaryInfo
]
=
[]
res
:
List
[
DiaryInfo
]
=
[]
...
...
card/views/live/format.py
View file @
2f986a20
...
@@ -11,10 +11,6 @@ from .schemas import LiveInfo, LiveList
...
@@ -11,10 +11,6 @@ from .schemas import LiveInfo, LiveList
class
LiveFormat
(
BaseFormat
):
class
LiveFormat
(
BaseFormat
):
def
__init__
(
self
,
version
,
device_id
):
self
.
version
=
version
self
.
device_id
=
device_id
@classmethod
@classmethod
def
_get_live_gm_url
(
cls
,
status
,
topic_id
,
channel_id
):
def
_get_live_gm_url
(
cls
,
status
,
topic_id
,
channel_id
):
"""获取直播相关的gm_url。"""
"""获取直播相关的gm_url。"""
...
...
card/views/live/live.py
View file @
2f986a20
...
@@ -36,7 +36,7 @@ async def live_list_by_ids(ctx: Context, request: LiveListRequest) -> LiveList:
...
@@ -36,7 +36,7 @@ async def live_list_by_ids(ctx: Context, request: LiveListRequest) -> LiveList:
user_id
=
request
.
user_id
user_id
=
request
.
user_id
res
=
(
await
get_current_rpc_invoker
()[
"mimas/live/get_clannels_url/audience"
](
res
=
(
await
get_current_rpc_invoker
()[
"mimas/live/get_clannels_url/audience"
](
ids
=
request
.
live_ids
,
ids
=
request
.
live_ids
,
#
user_id=user_id,
user_id
=
user_id
,
))
.
unwrap
()
))
.
unwrap
()
return
await
format_lives
(
request
.
version
,
request
.
device_id
,
res
)
return
await
format_lives
(
request
.
version
,
request
.
device_id
,
res
)
...
...
card/views/qa/format.py
View file @
2f986a20
...
@@ -5,20 +5,17 @@ from typing import List
...
@@ -5,20 +5,17 @@ from typing import List
from
gm_types.gaia
import
SEARCH_TAB_TYPE
from
gm_types.gaia
import
SEARCH_TAB_TYPE
from
gm_upload.utils.image_utils
import
Picture
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.schemas
import
User
,
Tag
from
card.views.utils.tag
import
transform_tags
from
card.views.utils.tag
import
transform_tags
from
card.libs.protocol
import
gm_protocol
from
card.libs.protocol
import
gm_protocol
from
card.views.utils.format
import
BaseFormat
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
from
.default_pic
import
default_pic
class
AnswerFormat
(
BaseFormat
):
class
AnswerFormat
(
BaseFormat
):
def
__init__
(
self
,
version
,
device_id
):
self
.
version
=
version
self
.
device_id
=
device_id
@classmethod
@classmethod
def
deal_with_pic_hex
(
cls
,
image
):
def
deal_with_pic_hex
(
cls
,
image
):
...
@@ -95,3 +92,49 @@ class AnswerFormat(BaseFormat):
...
@@ -95,3 +92,49 @@ class AnswerFormat(BaseFormat):
res
.
append
(
answer
)
res
.
append
(
answer
)
return
AnswerList
(
answers
=
res
)
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
)
card/views/qa/qa.py
View file @
2f986a20
from
fastapi_rpcd.all
import
Context
,
bind
# type: ignore
from
fastapi_rpcd.all
import
Context
,
bind
# type: ignore
from
fastapi_rpcd.all
import
get_current_rpc_invoker
from
fastapi_rpcd.all
import
get_current_rpc_invoker
from
.schemas
import
AnswerListRequest
,
AnswerList
from
.schemas
import
AnswerListRequest
,
AnswerList
,
QuestionListRequest
,
QuestionList
from
.format
import
AnswerFormat
from
.format
import
AnswerFormat
,
QuestionFormat
@bind
(
"card/answer/list_by_ids"
)
@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
:
if
not
request
.
answer_ids
:
return
AnswerList
(
answers
=
[])
return
AnswerList
(
answers
=
[])
...
@@ -14,7 +14,21 @@ async def diary_list_by_ids(ctx: Context, request: AnswerListRequest) -> AnswerL
...
@@ -14,7 +14,21 @@ async def diary_list_by_ids(ctx: Context, request: AnswerListRequest) -> AnswerL
user_id
=
request
.
user_id
user_id
=
request
.
user_id
res
=
(
await
get_current_rpc_invoker
()[
"qa/question_answer/list_by_ids_v3"
](
res
=
(
await
get_current_rpc_invoker
()[
"qa/question_answer/list_by_ids_v3"
](
answer_ids
=
request
.
answer_ids
,
answer_ids
=
request
.
answer_ids
,
#
user_id=user_id,
user_id
=
user_id
,
))
.
unwrap
()
))
.
unwrap
()
return
AnswerFormat
(
request
.
version
,
request
.
device_id
)
.
format_feed_card
(
res
)
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
)
card/views/qa/schemas.py
View file @
2f986a20
...
@@ -3,7 +3,7 @@ from typing import List, Optional
...
@@ -3,7 +3,7 @@ from typing import List, Optional
from
fastapi_rpcd.all
import
Schema
from
fastapi_rpcd.all
import
Schema
from
pydantic
import
Field
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
):
class
AnswerListRequest
(
Schema
):
...
@@ -20,7 +20,6 @@ class QaImage(Schema):
...
@@ -20,7 +20,6 @@ class QaImage(Schema):
image_webp
:
str
=
Field
(
...
,
description
=
"webp图片地址"
)
image_webp
:
str
=
Field
(
...
,
description
=
"webp图片地址"
)
height
:
int
=
Field
(
0
,
description
=
"图片地址"
)
height
:
int
=
Field
(
0
,
description
=
"图片地址"
)
width
:
str
=
Field
(
0
,
description
=
"图片地址"
)
width
:
str
=
Field
(
0
,
description
=
"图片地址"
)
image_url
:
str
=
Field
(
...
,
description
=
"图片地址"
)
class
AnswerInfo
(
Schema
):
class
AnswerInfo
(
Schema
):
...
@@ -29,7 +28,6 @@ class AnswerInfo(Schema):
...
@@ -29,7 +28,6 @@ class AnswerInfo(Schema):
id
:
int
=
Field
(
...
,
description
=
"问答ID"
)
id
:
int
=
Field
(
...
,
description
=
"问答ID"
)
title
:
str
=
Field
(
...
,
description
=
"问答标题"
)
title
:
str
=
Field
(
...
,
description
=
"问答标题"
)
content
:
str
=
Field
(
...
,
description
=
"内容"
)
content
:
str
=
Field
(
...
,
description
=
"内容"
)
service_id
:
str
=
Field
(
None
,
description
=
"日记关联美购ID"
)
is_voted
:
bool
=
Field
(
False
,
description
=
"是否点赞"
)
is_voted
:
bool
=
Field
(
False
,
description
=
"是否点赞"
)
vote_num
:
int
=
Field
(
0
,
description
=
"点赞数"
)
vote_num
:
int
=
Field
(
0
,
description
=
"点赞数"
)
answer_num
:
int
=
Field
(
0
,
description
=
"对应问题回答数"
)
answer_num
:
int
=
Field
(
0
,
description
=
"对应问题回答数"
)
...
@@ -45,3 +43,63 @@ class AnswerList(Schema):
...
@@ -45,3 +43,63 @@ class AnswerList(Schema):
"""问答卡片列表信息"""
"""问答卡片列表信息"""
answers
:
Optional
[
List
[
AnswerInfo
]]
=
Field
([],
description
=
"问答列表"
)
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
=
"问题列表"
)
card/views/special_pool/format.py
View file @
2f986a20
...
@@ -8,10 +8,6 @@ from .schemas import SpecialPoolInfo, SpecialPoolList, VisualPageInfo, VisualPag
...
@@ -8,10 +8,6 @@ from .schemas import SpecialPoolInfo, SpecialPoolList, VisualPageInfo, VisualPag
class
SpecialPoolFormat
(
BaseFormat
):
class
SpecialPoolFormat
(
BaseFormat
):
def
__init__
(
self
,
version
,
device_id
):
self
.
version
=
version
self
.
device_id
=
device_id
def
format_special_pool
(
self
,
info
):
def
format_special_pool
(
self
,
info
):
special_pool
=
{
special_pool
=
{
...
@@ -39,10 +35,6 @@ class SpecialPoolFormat(BaseFormat):
...
@@ -39,10 +35,6 @@ class SpecialPoolFormat(BaseFormat):
class
VisualPageFormat
(
BaseFormat
):
class
VisualPageFormat
(
BaseFormat
):
def
__init__
(
self
,
version
,
device_id
):
self
.
version
=
version
self
.
device_id
=
device_id
def
format_visual_page
(
self
,
info
):
def
format_visual_page
(
self
,
info
):
visual_page
=
{
visual_page
=
{
...
...
card/views/tractate/format.py
View file @
2f986a20
from
card.views.utils.html
import
gm_decode_html
import
copy
import
copy
from
typing
import
List
from
typing
import
List
...
@@ -7,8 +6,9 @@ from gm_types.mimas import TRACTATE_COVER_TYPE
...
@@ -7,8 +6,9 @@ from gm_types.mimas import TRACTATE_COVER_TYPE
from
gm_upload.utils.image_utils
import
Picture
from
gm_upload.utils.image_utils
import
Picture
from
card
import
settings
from
card
import
settings
from
card.views.schemas
import
User
,
Tag
from
card.views.schemas
import
Tag
from
card.views.utils.tag
import
feed_tag_v3_show_filter
,
transform_tags
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.libs.protocol
import
gm_protocol
from
card.views.utils.format
import
BaseFormat
from
card.views.utils.format
import
BaseFormat
from
.schemas
import
Image
,
TractateList
,
TractateInfo
from
.schemas
import
Image
,
TractateList
,
TractateInfo
...
@@ -16,10 +16,6 @@ from .schemas import Image, TractateList, TractateInfo
...
@@ -16,10 +16,6 @@ from .schemas import Image, TractateList, TractateInfo
class
TractateFormat
(
BaseFormat
):
class
TractateFormat
(
BaseFormat
):
def
__init__
(
self
,
version
,
device_id
):
self
.
version
=
version
self
.
device_id
=
device_id
@classmethod
@classmethod
def
convert_tags
(
cls
,
tags
,
tag_version
):
def
convert_tags
(
cls
,
tags
,
tag_version
):
...
...
card/views/tractate/tractate.py
View file @
2f986a20
...
@@ -6,7 +6,7 @@ from .format import TractateFormat
...
@@ -6,7 +6,7 @@ from .format import TractateFormat
@bind
(
"card/tractate/list_by_ids"
)
@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
:
if
not
request
.
tractate_ids
:
return
TractateList
(
tractates
=
[])
return
TractateList
(
tractates
=
[])
...
@@ -14,7 +14,7 @@ async def diary_list_by_ids(ctx: Context, request: TractateListRequest) -> Tract
...
@@ -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"
](
res
=
(
await
get_current_rpc_invoker
()[
"mimas/tractate/list_by_ids"
](
tractate_ids
=
request
.
tractate_ids
,
tractate_ids
=
request
.
tractate_ids
,
need_special_info
=
True
,
need_special_info
=
True
,
#
user_id=user_id,
user_id
=
user_id
,
))
.
unwrap
()
))
.
unwrap
()
tractates
=
res
.
get
(
"tractate_list"
,
[])
tractates
=
res
.
get
(
"tractate_list"
,
[])
...
...
card/views/utils/format.py
View file @
2f986a20
...
@@ -8,6 +8,10 @@ from card import settings
...
@@ -8,6 +8,10 @@ from card import settings
class
BaseFormat
(
object
):
class
BaseFormat
(
object
):
def
__init__
(
self
,
version
,
device_id
):
self
.
version
=
version
self
.
device_id
=
device_id
@classmethod
@classmethod
def
revert_image
(
cls
,
image
):
def
revert_image
(
cls
,
image
):
"""传入图片地址,返回原图(不带后缀)"""
"""传入图片地址,返回原图(不带后缀)"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment