refactor: 在后端处理字段映射与 invalid 判断 (#367)
This commit is contained in:
@@ -416,7 +416,8 @@ pub async fn get_created_favorites(
|
||||
.map(|fav| FavoriteWithSubscriptionStatus {
|
||||
title: fav.title,
|
||||
media_count: fav.media_count,
|
||||
fid: fav.fid,
|
||||
// api 返回的 id 才是真实的 fid
|
||||
fid: fav.id,
|
||||
mid: fav.mid,
|
||||
subscribed: subscribed_set.contains(&fav.id),
|
||||
})
|
||||
@@ -448,7 +449,7 @@ pub async fn get_followed_collections(
|
||||
let (page_num, page_size) = (params.page_num.unwrap_or(1), params.page_size.unwrap_or(50));
|
||||
let bili_collections = me.get_followed_collections(page_num, page_size).await?;
|
||||
|
||||
let collections = if let Some(collection_list) = &bili_collections.list {
|
||||
let collections = if let Some(collection_list) = bili_collections.list {
|
||||
let bili_sids: Vec<_> = collection_list.iter().map(|col| col.id).collect();
|
||||
|
||||
let subscribed_ids: Vec<i64> = collection::Entity::find()
|
||||
@@ -461,12 +462,12 @@ pub async fn get_followed_collections(
|
||||
let subscribed_set: HashSet<i64> = subscribed_ids.into_iter().collect();
|
||||
|
||||
collection_list
|
||||
.iter()
|
||||
.into_iter()
|
||||
.map(|col| CollectionWithSubscriptionStatus {
|
||||
id: col.id,
|
||||
title: col.title,
|
||||
sid: col.id,
|
||||
mid: col.mid,
|
||||
state: col.state,
|
||||
title: col.title.clone(),
|
||||
invalid: col.state == 1,
|
||||
subscribed: subscribed_set.contains(&col.id),
|
||||
})
|
||||
.collect()
|
||||
@@ -515,6 +516,8 @@ pub async fn get_followed_uppers(
|
||||
.into_iter()
|
||||
.map(|upper| UpperWithSubscriptionStatus {
|
||||
mid: upper.mid,
|
||||
// 官方没有提供字段,但是可以使用这种方式简单判断下
|
||||
invalid: upper.uname == "账号已注销" && upper.face == "https://i0.hdslb.com/bfs/face/member/noface.jpg",
|
||||
uname: upper.uname,
|
||||
face: upper.face,
|
||||
sign: upper.sign,
|
||||
@@ -576,7 +579,7 @@ pub async fn upsert_collection(
|
||||
let collection = Collection::new(
|
||||
bili_client.as_ref(),
|
||||
CollectionItem {
|
||||
sid: request.id.to_string(),
|
||||
sid: request.sid.to_string(),
|
||||
mid: request.mid.to_string(),
|
||||
collection_type: request.collection_type,
|
||||
},
|
||||
|
||||
@@ -60,7 +60,7 @@ pub struct UpsertFavoriteRequest {
|
||||
|
||||
#[derive(Deserialize, ToSchema, Validate)]
|
||||
pub struct UpsertCollectionRequest {
|
||||
pub id: i64,
|
||||
pub sid: i64,
|
||||
pub mid: i64,
|
||||
#[schema(value_type = i8)]
|
||||
#[serde(default)]
|
||||
|
||||
@@ -102,10 +102,10 @@ pub struct FavoriteWithSubscriptionStatus {
|
||||
|
||||
#[derive(Serialize, ToSchema)]
|
||||
pub struct CollectionWithSubscriptionStatus {
|
||||
pub id: i64,
|
||||
pub mid: i64,
|
||||
pub state: i32,
|
||||
pub title: String,
|
||||
pub sid: i64,
|
||||
pub mid: i64,
|
||||
pub invalid: bool,
|
||||
pub subscribed: bool,
|
||||
}
|
||||
|
||||
@@ -115,6 +115,7 @@ pub struct UpperWithSubscriptionStatus {
|
||||
pub uname: String,
|
||||
pub face: String,
|
||||
pub sign: String,
|
||||
pub invalid: bool,
|
||||
pub subscribed: bool,
|
||||
}
|
||||
|
||||
|
||||
@@ -89,14 +89,9 @@
|
||||
function isDisabled(): boolean {
|
||||
switch (type) {
|
||||
case 'collection':
|
||||
return (item as CollectionWithSubscriptionStatus).state === 1;
|
||||
return (item as CollectionWithSubscriptionStatus).invalid;
|
||||
case 'upper': {
|
||||
const upper = item as UpperWithSubscriptionStatus;
|
||||
// 没看到有 status 标记,这样判断应该没什么大问题
|
||||
return (
|
||||
upper.uname === '账号已注销' &&
|
||||
upper.face === 'https://i0.hdslb.com/bfs/face/member/noface.jpg'
|
||||
);
|
||||
return (item as UpperWithSubscriptionStatus).invalid;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
|
||||
@@ -95,9 +95,7 @@
|
||||
case 'favorite': {
|
||||
const favorite = item as FavoriteWithSubscriptionStatus;
|
||||
const request: UpsertFavoriteRequest = {
|
||||
// 数据库中保存的 fid 实际上是 favorite.id
|
||||
fid: favorite.id,
|
||||
name: favorite.title,
|
||||
fid: favorite.fid,
|
||||
path: customPath.trim()
|
||||
};
|
||||
response = await api.upsertFavorite(request);
|
||||
@@ -106,7 +104,7 @@
|
||||
case 'collection': {
|
||||
const collection = item as CollectionWithSubscriptionStatus;
|
||||
const request: UpsertCollectionRequest = {
|
||||
id: collection.id,
|
||||
sid: collection.sid,
|
||||
mid: collection.mid,
|
||||
path: customPath.trim()
|
||||
};
|
||||
|
||||
@@ -107,7 +107,6 @@ export interface UpdateVideoStatusResponse {
|
||||
export interface FavoriteWithSubscriptionStatus {
|
||||
title: string;
|
||||
media_count: number;
|
||||
id: number;
|
||||
fid: number;
|
||||
mid: number;
|
||||
subscribed: boolean;
|
||||
@@ -119,10 +118,10 @@ export interface FavoritesResponse {
|
||||
|
||||
// 合集相关类型
|
||||
export interface CollectionWithSubscriptionStatus {
|
||||
id: number;
|
||||
mid: number;
|
||||
state: number;
|
||||
title: string;
|
||||
sid: number;
|
||||
mid: number;
|
||||
invalid: boolean;
|
||||
subscribed: boolean;
|
||||
}
|
||||
|
||||
@@ -137,6 +136,7 @@ export interface UpperWithSubscriptionStatus {
|
||||
uname: string;
|
||||
face: string;
|
||||
sign: string;
|
||||
invalid: boolean;
|
||||
subscribed: boolean;
|
||||
}
|
||||
|
||||
@@ -147,12 +147,11 @@ export interface UppersResponse {
|
||||
|
||||
export interface UpsertFavoriteRequest {
|
||||
fid: number;
|
||||
name: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface UpsertCollectionRequest {
|
||||
id: number;
|
||||
sid: number;
|
||||
mid: number;
|
||||
path: string;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
<div
|
||||
style="display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; width: 100%; max-width: none; justify-items: start;"
|
||||
>
|
||||
{#each collections as collection (collection.id)}
|
||||
{#each collections as collection (collection.sid)}
|
||||
<div style="max-width: 450px; width: 100%;">
|
||||
<SubscriptionCard
|
||||
item={collection}
|
||||
|
||||
Reference in New Issue
Block a user