mirror of
https://github.com/PaiGramTeam/FixMiYouShe.git
synced 2024-11-16 04:45:40 +00:00
✨ Add image params
This commit is contained in:
parent
42d6108b48
commit
939d22ffa3
@ -51,7 +51,7 @@ class Hyperion:
|
||||
auto_orient: int = 0,
|
||||
interlace: int = 1,
|
||||
images_format: str = "jpg",
|
||||
):
|
||||
) -> str:
|
||||
"""
|
||||
image/resize,s_600/quality,q_80/auto-orient,0/interlace,1/format,jpg
|
||||
:param resize: 图片大小
|
||||
@ -65,7 +65,7 @@ class Hyperion:
|
||||
f"image/resize,s_{resize}/quality,q_{quality}/auto-orient,"
|
||||
f"{auto_orient}/interlace,{interlace}/format,{images_format}"
|
||||
)
|
||||
return {"x-oss-process": params}
|
||||
return f"?x-oss-process={params}"
|
||||
|
||||
async def get_post_full_in_collection(
|
||||
self, collection_id: int, gids: int = 2, order_type=1
|
||||
|
@ -18,6 +18,11 @@ class PostStat(BaseModel):
|
||||
bookmark_num: int = 0
|
||||
|
||||
|
||||
class PostTopic(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
|
||||
|
||||
class PostType(int, Enum):
|
||||
"""帖子类型"""
|
||||
|
||||
@ -36,6 +41,7 @@ class PostInfo(BaseModel):
|
||||
video_urls: List[str]
|
||||
content: str
|
||||
cover: Optional[str]
|
||||
topics: List[PostTopic]
|
||||
view_type: PostType
|
||||
stat: PostStat
|
||||
|
||||
@ -58,6 +64,7 @@ class PostInfo(BaseModel):
|
||||
user_uid = user["uid"] # 用户ID
|
||||
content = post["content"]
|
||||
cover = post["cover"]
|
||||
topics = [PostTopic(**topic) for topic in _data_post["topics"]]
|
||||
view_type = PostType(post["view_type"])
|
||||
stat = PostStat(**_data_post["stat"])
|
||||
return PostInfo(
|
||||
@ -70,6 +77,7 @@ class PostInfo(BaseModel):
|
||||
created_at=created_at,
|
||||
content=content,
|
||||
cover=cover,
|
||||
topics=topics,
|
||||
view_type=view_type,
|
||||
stat=stat,
|
||||
)
|
||||
|
@ -40,6 +40,12 @@ def get_description(soup: BeautifulSoup) -> str:
|
||||
return post_text
|
||||
|
||||
|
||||
def format_image_url(url: str) -> str:
|
||||
if url.endswith(".png") or url.endswith(".jpg"):
|
||||
return f'<img src="{url}{Hyperion.get_images_params()}"/>'
|
||||
return url
|
||||
|
||||
|
||||
def parse_tag(tag: Union[Tag, PageElement]) -> str:
|
||||
if tag.name == "a":
|
||||
href = tag.get("href")
|
||||
@ -49,9 +55,8 @@ def parse_tag(tag: Union[Tag, PageElement]) -> str:
|
||||
return f'<a href="{href}">{tag.get_text()}</a>'
|
||||
elif tag.name == "img":
|
||||
src = tag.get("src")
|
||||
# fix telegram fetch url failed
|
||||
if src and "upload-bbs.miyoushe.com" in src:
|
||||
return str(tag)
|
||||
return format_image_url(src)
|
||||
return ""
|
||||
elif tag.name == "p":
|
||||
t = tag.get_text()
|
||||
@ -102,6 +107,7 @@ def get_public_data(game_id: str, post_id: int, post_info: PostInfo) -> Dict:
|
||||
),
|
||||
"channel": CHANNEL_MAP.get(game_id, "HSRCN"),
|
||||
"stat": parse_stat(post_info.stat),
|
||||
"game_id": game_id,
|
||||
"post": post_info,
|
||||
"author": post_info["post"]["user"],
|
||||
}
|
||||
@ -121,7 +127,7 @@ async def process_article_image(game_id: str, post_id: int, post_info: PostInfo)
|
||||
description = json_data.get("describe", "")
|
||||
article = ""
|
||||
for image in json_data.get("imgs", []):
|
||||
article += f'<img src="{image}"/>\n'
|
||||
article += format_image_url(image)
|
||||
if description:
|
||||
article += f"<p>{description}</p>\n"
|
||||
return template.render(
|
||||
|
@ -46,6 +46,14 @@ Embed MiYouShe posts, videos, polls, and more on Telegram
|
||||
{{ article }}
|
||||
<!-- stat -->
|
||||
{{ stat }}
|
||||
<!-- topics -->
|
||||
{% if post.topics %}
|
||||
<p>
|
||||
{% for topic in post.topics %}
|
||||
<a href="https://www.miyoushe.com/{{ game_id }}/topicDetail/{{ topic.id }}">#{{ topic.name }} </a>
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
<p><a href="{{ url }}">查看原文</a></p>
|
||||
<!-- author -->
|
||||
<h3>作者信息</h3>
|
||||
@ -54,7 +62,7 @@ Embed MiYouShe posts, videos, polls, and more on Telegram
|
||||
{% endif %}
|
||||
<h2>{{ author.nickname }}</h2>
|
||||
<p>
|
||||
<a href="https://www.miyoushe.com/sr/accountCenter/postList?id={{ author.uid }}">@{{ author.nickname }}</a>
|
||||
<a href="https://www.miyoushe.com/{{ game_id }}/accountCenter/postList?id={{ author.uid }}">@{{ author.nickname }}</a>
|
||||
lv.{{ author.level_exp.level }}
|
||||
</p>
|
||||
<p><a href="{{ url }}">查看原文</a></p>
|
||||
|
Loading…
Reference in New Issue
Block a user