diff --git a/BilibiliLive/Component/Video/VideoDetailViewController.swift b/BilibiliLive/Component/Video/VideoDetailViewController.swift index 0fbf82c..d90dc0a 100644 --- a/BilibiliLive/Component/Video/VideoDetailViewController.swift +++ b/BilibiliLive/Component/Video/VideoDetailViewController.swift @@ -429,6 +429,12 @@ class VideoDetailViewController: UIViewController { guard let favList = try? await WebRequest.requestFavVideosList() else { return } + if favButton.isOn { + favButton.title? -= 1 + favButton.isOn = false + WebRequest.removeFavorite(aid: aid, mid: favList.map { $0.id }) + return + } let alert = UIAlertController(title: "收藏", message: nil, preferredStyle: .actionSheet) let aid = aid for fav in favList { diff --git a/BilibiliLive/Request/WebRequest.swift b/BilibiliLive/Request/WebRequest.swift index 8ed2b08..0c6dd2b 100644 --- a/BilibiliLive/Request/WebRequest.swift +++ b/BilibiliLive/Request/WebRequest.swift @@ -394,6 +394,10 @@ extension WebRequest { requestJSON(method: .post, url: "https://api.bilibili.com/x/v3/fav/resource/deal", parameters: ["rid": aid, "type": 2, "add_media_ids": mid]) } + static func removeFavorite(aid: Int, mid: [Int]) { + requestJSON(method: .post, url: "https://api.bilibili.com/x/v3/fav/resource/deal", parameters: ["rid": aid, "type": 2, "del_media_ids": mid.map { "\($0)" }.joined(separator: ",")]) + } + static func requestFavoriteStatus(aid: Int, complete: ((Bool) -> Void)?) { requestJSON(url: "https://api.bilibili.com/x/v2/fav/video/favoured", parameters: ["aid": aid]) { response in