添加取消收藏功能
This commit is contained in:
@@ -38,4 +38,28 @@ export const BilibiliClientVideoActionMethods = {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
// 取消收藏视频从默认收藏夹
|
||||
async unstarVideoFromDefaultFavFolderByBVID(this: any, bvid: string): Promise<any> {
|
||||
let defaultFolderID = 0;
|
||||
const folders = await this.getUserFavouriteFolders(this.accountInfo.mid);
|
||||
folders.list.forEach((folder: any) => {
|
||||
if (folder.title === "默认收藏夹") {
|
||||
defaultFolderID = folder.id;
|
||||
}
|
||||
});
|
||||
if (!defaultFolderID) return false;
|
||||
|
||||
try {
|
||||
const videoInfo = await this.getVideoInfoByBVID(bvid);
|
||||
const aid = videoInfo.aid;
|
||||
const url = `https://api.bilibili.com/x/v3/fav/resource/deal`;
|
||||
const data = `rid=${aid}&csrf=${this.biliJct}&type=2&add_media_ids=&del_media_ids=${defaultFolderID}`;
|
||||
const response = await this.postRequest(url, data, "application/x-www-form-urlencoded");
|
||||
return response.data.code;
|
||||
} catch (error) {
|
||||
global.logger.error("Error unstarring video: ", error);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -220,9 +220,16 @@ export default {
|
||||
})
|
||||
},
|
||||
async AddToFav() {
|
||||
const result = await global.biliclient.starVideoToDefaultFavFolderByBVID(this.bvid)
|
||||
const message = result ? "收藏失败,请重试,或重新登录后再试" : "收藏成功"
|
||||
prompt.showToast({message})
|
||||
let result;
|
||||
if (this.stared) {
|
||||
result = await global.biliclient.unstarVideoFromDefaultFavFolderByBVID(this.bvid)
|
||||
const message = result === 0 ? "取消收藏成功" : "取消收藏失败,请重试,或重新登录后再试"
|
||||
prompt.showToast({message})
|
||||
} else {
|
||||
result = await global.biliclient.starVideoToDefaultFavFolderByBVID(this.bvid)
|
||||
const message = result === 0 ? "收藏成功" : "收藏失败,请重试,或重新登录后再试"
|
||||
prompt.showToast({message})
|
||||
}
|
||||
this.UpdateVideoToolbarStatus()
|
||||
},
|
||||
async GenBlur(evt) {
|
||||
|
||||
Reference in New Issue
Block a user