Skip to content

Commit

Permalink
Fix Bilibili Updated Crash Issue (#43)
Browse files Browse the repository at this point in the history
* Branch first commit, to create pr & run UI test

* Fast update for testing

* Update ui-test.yml

* Update ui-test.yml

* Updated some files

* Fixed - Add UserAgent to all requests

* Fix build issue
  • Loading branch information
WindowsMEMZ authored Dec 30, 2023
1 parent bffcd39 commit 193675b
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ui-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ jobs:
echo "FIN_STATUS=success" >> $GITHUB_ENV
- name: Process Test Result
if: always()
run: |
mv ~/Library/Developer/Xcode/DerivedData/DarockBili-*/Logs/Test/Test-*.xcresult ./Caches/Test-1.xcresult
mkdir Caches/ExportFiles
xcparse -s ./Caches/Test-1.xcresult ./Caches/ExportFiles
- name: Upload Test Attachments
if: always()
uses: actions/upload-artifact@v3
with:
name: Test Attachments
Expand Down
2 changes: 1 addition & 1 deletion DarockBili Watch App/DarockBiliApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import SDWebImageSVGCoder
import SDWebImageWebPCoder

//!!!: Debug Setting, Set false Before Release
var debug = true
var debug = false

var debugControlStdout = "stdo\n"

Expand Down
5 changes: 4 additions & 1 deletion DarockBili Watch App/Extension/CodeExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ func biliWbiSign(paramEncoded: String, completion: @escaping (String?) -> Void)
}

func getWbiKeys(completion: @escaping (Result<(imgKey: String, subKey: String), Error>) -> Void) {
AF.request("https://api.bilibili.com/x/web-interface/nav").responseJSON { response in
let headers: HTTPHeaders = [
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
AF.request("https://api.bilibili.com/x/web-interface/nav", headers: headers).responseJSON { response in
switch response.result {
case .success(let value):
let json = JSON(value)
Expand Down
3 changes: 2 additions & 1 deletion DarockBili Watch App/InMain/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ struct MainView: View {
isLoadingNew = true
isFailedToLoad = false
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata)"
"cookie": "SESSDATA=\(sessdata)",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
biliWbiSign(paramEncoded: "ps=\(isInLowBatteryMode ? 10 : 30)".base64Encoded()) { signed in
if let signed {
Expand Down
12 changes: 9 additions & 3 deletions DarockBili Watch App/Others/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ struct LoginView: View {
}
.tag(0)
.onAppear {
DarockKit.Network.shared.requestJSON("https://passport.bilibili.com/x/passport-login/web/qrcode/generate") { respJson, isSuccess in
let headers: HTTPHeaders = [
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
DarockKit.Network.shared.requestJSON("https://passport.bilibili.com/x/passport-login/web/qrcode/generate", headers: headers) { respJson, isSuccess in
if isSuccess {
let qrUrl = respJson["data"]["url"].string!.replacingOccurrences(of: "\\u0026", with: "&")
debugPrint(qrUrl)
Expand All @@ -83,7 +86,7 @@ struct LoginView: View {
qrKey = respJson["data"]["qrcode_key"].string!
Timer.scheduledTimer(withTimeInterval: 2.0, repeats: true) { timer in
qrTimer = timer
DarockKit.Network.shared.requestJSON("https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key=\(qrKey)") { respJson, isSuccess in
DarockKit.Network.shared.requestJSON("https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key=\(qrKey)", headers: headers) { respJson, isSuccess in
if respJson["data"]["code"].int == 86090 {
isScanned = true
} else if respJson["data"]["code"].int == 0 {
Expand Down Expand Up @@ -195,7 +198,10 @@ struct LoginView: View {
}
.tag(1)
.onAppear {
DarockKit.Network.shared.requestJSON("https://passport.bilibili.com/x/passport-login/captcha?source=main_web") { respJson, isSuccess in
let headers: HTTPHeaders = [
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
DarockKit.Network.shared.requestJSON("https://passport.bilibili.com/x/passport-login/captcha?source=main_web", headers: headers) { respJson, isSuccess in
if isSuccess {
challenge = respJson["data"]["geetest"]["challenge"].string!
gt = respJson["data"]["geetest"]["gt"].string!
Expand Down
6 changes: 4 additions & 2 deletions DarockBili Watch App/PersonalCenter/FavoriteView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ struct FavoriteView: View {
.onAppear {
if !isLoaded {
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata);"
"cookie": "SESSDATA=\(sessdata);",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/v3/fav/folder/created/list-all?up_mid=\(dedeUserID)", headers: headers) { respJson, isSuccess in
if isSuccess {
Expand Down Expand Up @@ -109,7 +110,8 @@ struct FavoriteDetailView: View {
func RefreshDetailData() {
details.removeAll()
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata);"
"cookie": "SESSDATA=\(sessdata);",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/v3/fav/resource/list?media_id=\(folderDatas["ID"]!)&ps=20&pn=\(nowPage)", headers: headers) { respJson, isSuccess in
if isSuccess {
Expand Down
7 changes: 6 additions & 1 deletion DarockBili Watch App/PersonalCenter/FollowListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import SwiftUI
import DarockKit
import Alamofire
import SwiftyJSON
import SDWebImageSwiftUI

Expand Down Expand Up @@ -114,7 +115,11 @@ struct FollowListView: View {
}
}
func RefreshNew() {
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/relation/followings?vmid=\(viewUserId)&order_type=&ps=20&pn=\(nowPage)") { respJson, isSuccess in
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata);",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/relation/followings?vmid=\(viewUserId)&order_type=&ps=20&pn=\(nowPage)", headers: headers) { respJson, isSuccess in
if isSuccess {
let datas = respJson["data"]["list"]
for data in datas {
Expand Down
3 changes: 2 additions & 1 deletion DarockBili Watch App/PersonalCenter/HistoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ struct HistoryView: View {
.onAppear {
if !isLoaded {
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata);"
"cookie": "SESSDATA=\(sessdata);",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/v2/history", headers: headers) { respJson, isSuccess in
if isSuccess {
Expand Down
3 changes: 2 additions & 1 deletion DarockBili Watch App/PersonalCenter/PersonAccountView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ struct PersonAccountView: View {
.navigationBarTitleDisplayMode(.large)
.onAppear {
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata);"
"cookie": "SESSDATA=\(sessdata);",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/member/web/account", headers: headers) { respJson, isSuccess in
if isSuccess {
Expand Down
10 changes: 6 additions & 4 deletions DarockBili Watch App/PersonalCenter/UserDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ struct UserDetailView: View {
}
.onAppear {
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata);"
"cookie": "SESSDATA=\(sessdata);",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
biliWbiSign(paramEncoded: "mid=\(uid)".base64Encoded()) { signed in
if let signed {
Expand All @@ -164,7 +165,7 @@ struct UserDetailView: View {
officialTitle = respJson["data"]["official"]["title"].string ?? ""
userSign = respJson["data"]["sign"].string ?? "[加载失败]"
coinCount = respJson["data"]["coins"].int ?? -1
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/relation/stat?vmid=\(uid)") { respJson, isSuccess in
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/relation/stat?vmid=\(uid)", headers: headers) { respJson, isSuccess in
if isSuccess {
followCount = respJson["data"]["following"].int ?? -1
fansCount = respJson["data"]["follower"].int ?? -1
Expand All @@ -174,7 +175,7 @@ struct UserDetailView: View {
}
}
}
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/relation?fid=\(uid)") { respJson, isSuccess in
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/relation?fid=\(uid)", headers: headers) { respJson, isSuccess in
if isSuccess {
if respJson["data"]["attribute"].int ?? 0 == 2 || respJson["data"]["attribute"].int ?? 0 == 6 {
isFollowed = true
Expand Down Expand Up @@ -251,7 +252,8 @@ struct UserDetailView: View {
}
Button(action: {
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata);"
"cookie": "SESSDATA=\(sessdata);",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
AF.request("https://api.bilibili.com/x/relation/modify", method: .post, parameters: ModifyUserRelation(fid: Int(uid)!, act: isFollowed ? 2 : 1, csrf: biliJct), headers: headers).response { response in
debugPrint(response)
Expand Down
3 changes: 2 additions & 1 deletion DarockBili Watch App/PersonalCenter/WatchLaterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ struct WatchLaterView: View {
}
.onAppear {
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata);"
"cookie": "SESSDATA=\(sessdata);",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/v2/history/toview", headers: headers) { respJson, isSuccess in
if isSuccess {
Expand Down
3 changes: 2 additions & 1 deletion DarockBili Watch App/UserDynamic/UserDynamicMainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ struct UserDynamicMainView: View {

func ContinueLoadDynamic() {
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata);"
"cookie": "SESSDATA=\(sessdata);",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?type=all\({ () -> String in if lastDynamicID != "" { return "&offset=\(lastDynamicID)"; } else { return ""; }; }())&page=\(nextLoadPage)", headers: headers) { respJson, isSuccess in
if isSuccess {
Expand Down
18 changes: 12 additions & 6 deletions DarockBili Watch App/Video/VideoCommentsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ struct VideoCommentsView: View {
.opacity(comments[i]["UserAction"]! == "1" ? 1 : 0.6)
.onTapGesture {
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata)"
"cookie": "SESSDATA=\(sessdata)",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
AF.request("https://api.bilibili.com/x/v2/reply/action", method: .post, parameters: BiliCommentLike(oid: avid, rpid: Int(comments[i]["Rpid"]!)!, action: comments[i]["UserAction"]! == "1" ? 0 : 1, csrf: biliJct), headers: headers).response { response in
debugPrint(response)
Expand All @@ -174,7 +175,8 @@ struct VideoCommentsView: View {
.opacity(comments[i]["UserAction"]! == "2" ? 1 : 0.6)
.onTapGesture {
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata)"
"cookie": "SESSDATA=\(sessdata)",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
AF.request("https://api.bilibili.com/x/v2/reply/hate", method: .post, parameters: BiliCommentLike(oid: avid, rpid: Int(comments[i]["Rpid"]!)!, action: comments[i]["UserAction"]! == "2" ? 0 : 1, csrf: biliJct), headers: headers).response { response in
debugPrint(response)
Expand Down Expand Up @@ -222,7 +224,8 @@ struct VideoCommentsView: View {
avid = bv2av(bvid: oid)
debugPrint(avid)
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata);"
"cookie": "SESSDATA=\(sessdata);",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/v2/reply?type=1&oid=\(avid)&sort=1&ps=20&pn=\(nowPage)", headers: headers) { respJson, isSuccess in
if isSuccess {
Expand Down Expand Up @@ -352,7 +355,8 @@ struct VideoCommentsView: View {
.opacity(replies[i]["UserAction"]! == "1" ? 1 : 0.6)
.onTapGesture {
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata)"
"cookie": "SESSDATA=\(sessdata)",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
AF.request("https://api.bilibili.com/x/v2/reply/action", method: .post, parameters: BiliCommentLike(oid: avid, rpid: Int(replies[i]["Rpid"]!)!, action: replies[i]["UserAction"]! == "1" ? 0 : 1, csrf: biliJct), headers: headers).response { response in
debugPrint(response)
Expand All @@ -367,7 +371,8 @@ struct VideoCommentsView: View {
.opacity(replies[i]["UserAction"]! == "2" ? 1 : 0.6)
.onTapGesture {
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata)"
"cookie": "SESSDATA=\(sessdata)",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
AF.request("https://api.bilibili.com/x/v2/reply/hate", method: .post, parameters: BiliCommentLike(oid: avid, rpid: Int(replies[i]["Rpid"]!)!, action: replies[i]["UserAction"]! == "2" ? 0 : 1, csrf: biliJct), headers: headers).response { response in
debugPrint(response)
Expand Down Expand Up @@ -420,7 +425,8 @@ struct VideoCommentsView: View {
.onSubmit {
if sendCommentCache != "" {
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata)"
"cookie": "SESSDATA=\(sessdata)",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
AF.request("https://api.bilibili.com/x/v2/reply/add", method: .post, parameters: BiliSubmitComment(oid: avid, message: sendCommentCache, csrf: biliJct), headers: headers).response { response in
sendCommentCache = ""
Expand Down
Loading

0 comments on commit 193675b

Please sign in to comment.