diff --git a/src/bilibiliclient/video/action.ts b/src/bilibiliclient/video/action.ts index fc62de5..250f2aa 100644 --- a/src/bilibiliclient/video/action.ts +++ b/src/bilibiliclient/video/action.ts @@ -38,4 +38,28 @@ export const BilibiliClientVideoActionMethods = { return false; } }, + + // 取消收藏视频从默认收藏夹 + async unstarVideoFromDefaultFavFolderByBVID(this: any, bvid: string): Promise { + 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; + } + }, } \ No newline at end of file diff --git a/src/pages/video/videodetail/videodetail.ux b/src/pages/video/videodetail/videodetail.ux index ae1bcd9..df93bc1 100644 --- a/src/pages/video/videodetail/videodetail.ux +++ b/src/pages/video/videodetail/videodetail.ux @@ -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) {