Skip to content

Commit

Permalink
[bilibili.space] Remove major URL if it has a module URL
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO committed Oct 14, 2024
1 parent 4f3f569 commit 9a833e0
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/source/platform/bilibili/space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl Fetcher {
}

async fn fetch_status_impl(&self) -> anyhow::Result<Status> {
let posts =
let mut posts =
fetch_space_history(self.params.user_id, self.blocked.lock().await.deref_mut()).await?;

Ok(Status::new(
Expand Down Expand Up @@ -547,44 +547,46 @@ fn parse_response(resp: data::SpaceHistory, blocked: &mut BlockedPostIds) -> any
parent_item.unwrap().id_str.as_ref().unwrap()
))
};
let mut urls = vec![major_url];
item.modules
let url = item
.modules
.dynamic
.major
.as_ref()
.inspect(|major| match major {
.and_then(|major| match major {
data::ModuleDynamicMajor::None(_)
| data::ModuleDynamicMajor::Opus(_)
| data::ModuleDynamicMajor::Draw(_)
| data::ModuleDynamicMajor::Common(_) => {
// No need to add extra URLs
None
}
data::ModuleDynamicMajor::Archive(archive) => urls.push(PostUrl::new_clickable(
data::ModuleDynamicMajor::Archive(archive) => Some(PostUrl::new_clickable(
format!("https://www.bilibili.com/video/{}", archive.archive.bvid),
"查看视频",
)),
data::ModuleDynamicMajor::Article(article) => urls.push(PostUrl::new_clickable(
data::ModuleDynamicMajor::Article(article) => Some(PostUrl::new_clickable(
format!("https://www.bilibili.com/read/cv{}", article.article.id),
"查看文章",
)),
data::ModuleDynamicMajor::Pgc(pgc) => urls.push(PostUrl::new_clickable(
data::ModuleDynamicMajor::Pgc(pgc) => Some(PostUrl::new_clickable(
format!("https://www.bilibili.com/bangumi/play/ep{}", pgc.pgc.epid),
"查看文章",
"查看剧集",
)),
data::ModuleDynamicMajor::Live(live) => urls.push(PostUrl::new_clickable(
data::ModuleDynamicMajor::Live(live) => Some(PostUrl::new_clickable(
format!("https://live.bilibili.com/{}", live.live.id),
"前往直播间",
)),
data::ModuleDynamicMajor::LiveRcmd | data::ModuleDynamicMajor::Blocked => {
critical!("unexpected major type: {major:?}");
unreachable!()
}
});
})
.unwrap_or(major_url);

Ok(Post {
user: Some(item.modules.author.clone().into()),
content,
urls: PostUrls::from_iter(urls)?,
urls: PostUrls::new(url),
repost_from: original.map(|original| RepostFrom::Recursion(Box::new(original))),
attachments: item
.modules
Expand Down

0 comments on commit 9a833e0

Please sign in to comment.