Skip to content

Commit

Permalink
修复长UID用户崩溃问题 (#36)
Browse files Browse the repository at this point in the history
* Update AboutView.swift

* Update AboutView.swift

* Update DarockBili_Watch_App_UI_Tests.swift

* Update AboutView.swift

* Update DarockBili_Watch_App_UI_Tests.swift

* Update DarockBili_Watch_App_UI_Tests.swift

* Update AboutView.swift

* Update DarockBili_Watch_App_UI_Tests.swift

* Update DarockBili_Watch_App_UI_Tests.swift

* Update DarockBili_Watch_App_UI_Tests.swift

* Updated UserDetailView

* Update UserDetailView.swift

* Update bMessageSendView.swift

* Update UserDetailView.swift

把视频列表请求用回了旧版本的,可能会好点

* Update AboutView.swift

* Update UserDetailView.swift

* Update DarockBili_Watch_App_UI_Tests.swift

* Update AboutView.swift
  • Loading branch information
WindowsMEMZ authored Jan 7, 2024
1 parent 5e418a5 commit ee0e522
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ final class DarockBili_Watch_App_UI_Tests: XCTestCase {
let app = XCUIApplication()
app.launch()
sleep(2)
// In Terms Page
takeScreenshot(of: app, named: "Launch")
app.buttons["关闭"].firstMatch.tap()
sleep(1)
// In main tabview first page (suggestions)
takeScreenshot(of: app, named: "Suggestions")
app.buttons["SuggestVideo"].firstMatch.tap()
sleep(1)
takeScreenshot(of: app, named: "RMVideo")
Expand Down Expand Up @@ -90,7 +94,6 @@ final class DarockBili_Watch_App_UI_Tests: XCTestCase {
app.swipeUp()
sleep(1)
takeScreenshot(of: app, named: "AboutView")

}

func testLaunchPerformance() throws {
Expand Down
15 changes: 15 additions & 0 deletions DarockBili Watch App/Others/AboutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ struct AboutView: View {
Text("开源组件许可")
})
}
//Section {
// NavigationLink(destination: {DebugUITestView()}, label: {
// Text("调试")
// })
//}
}
.bold()
}
Expand Down Expand Up @@ -104,6 +109,16 @@ struct AboutView: View {
}
}

struct DebugUITestView: View {
var body: some View {
List {
NavigationLink(destination: {UserDetailView(uid: "3546572635768935")}, label: {
Text("LongUIDUserTest")
})
}
}
}

struct AboutView_Previews: PreviewProvider {
static var previews: some View {
AboutView()
Expand Down
29 changes: 15 additions & 14 deletions DarockBili Watch App/PersonalCenter/UserDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct UserDetailView: View {
if #available(watchOS 10, *) {
TabView {
VStack {
NavigationLink("", isActive: $isSendbMessagePresented, destination: {bMessageSendView(uid: Int(uid)!, username: username)})
NavigationLink("", isActive: $isSendbMessagePresented, destination: {bMessageSendView(uid: Int64(uid)!, username: username)})
.frame(width: 0, height: 0)
FirstPageBase(uid: uid, userFaceUrl: $userFaceUrl, username: $username, followCount: $followCount, fansCount: $fansCount, coinCount: $coinCount, isFollowed: $isFollowed, isSendbMessagePresented: $isSendbMessagePresented)
.toolbar {
Expand All @@ -61,7 +61,7 @@ struct UserDetailView: View {
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata);"
]
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
AF.request("https://api.bilibili.com/x/relation/modify", method: .post, parameters: ModifyUserRelation(fid: Int64(uid)!, act: isFollowed ? 2 : 1, csrf: biliJct), headers: headers).response { response in
debugPrint(response)
let json = try! JSON(data: response.data!)
let code = json["code"].int!
Expand Down Expand Up @@ -152,7 +152,7 @@ struct UserDetailView: View {
debugPrint(signed)
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/space/wbi/acc/info?\(signed)", headers: headers) { respJson, isSuccess in
if isSuccess {
debugPrint(respJson)
//debugPrint(respJson)
if !CheckBApiError(from: respJson) { return }
userFaceUrl = respJson["data"]["face"].string ?? "E"
// AF.request(respJson["data"]["face"].string ?? "E").response { response in
Expand Down Expand Up @@ -257,7 +257,7 @@ struct UserDetailView: View {
"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
AF.request("https://api.bilibili.com/x/relation/modify", method: .post, parameters: ModifyUserRelation(fid: Int64(uid)!, act: isFollowed ? 2 : 1, csrf: biliJct), headers: headers).response { response in
debugPrint(response)
let json = try! JSON(data: response.data!)
let code = json["code"].int!
Expand All @@ -274,7 +274,7 @@ struct UserDetailView: View {
Text(isFollowed ? "取消关注" : "关注")
}
})
NavigationLink("", isActive: $isSendbMessagePresented, destination: {bMessageSendView(uid: Int(uid)!, username: username)})
NavigationLink("", isActive: $isSendbMessagePresented, destination: {bMessageSendView(uid: Int64(uid)!, username: username)})
.frame(width: 0, height: 0)
Button(action: {
isSendbMessagePresented = true
Expand Down Expand Up @@ -564,16 +564,17 @@ struct UserDetailView: View {
func RefreshVideos() {
videos = [[String: String]]()
let headers: HTTPHeaders = [
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"accept-language": "zh-CN,zh;q=0.9",
"cookie": "\(sessdata == "" ? "" : "SESSDATA=\(sessdata); ")buvid3=\(globalBuvid3); b_nut=\(Date.now.timeStamp); buvid4=\(globalBuvid4);",
"origin": "https://space.bilibili.com",
"referer": "https://space.bilibili.com/\(uid)/video",
"User-Agent": "Mozilla/5.0" // Bypass? drdar://gh/SocialSisterYi/bilibili-API-collect/issues/868/1859065874
//"accept": "*/*",
//"accept-encoding": "gzip, deflate, br",
//"accept-language": "zh-CN,zh;q=0.9",
//"cookie": "\(sessdata == "" ? "" : "SESSDATA=\(sessdata); ")buvid3=\(globalBuvid3); b_nut=\(Date.now.timeStamp); buvid4=\(globalBuvid4);",
"cookie": "SESSDATA=\(sessdata);"
//"origin": "https://space.bilibili.com",
//"referer": "https://space.bilibili.com/\(uid)/video",
//"User-Agent": "Mozilla/5.0" // Bypass? drdar://gh/SocialSisterYi/bilibili-API-collect/issues/868/1859065874
]
// FIXME: Official Wbi crypto logic for this request seems different from other APIs, some IP can get but some can't. It's hard to fix ~_~
biliWbiSign(paramEncoded: "mid=\(uid)&ps=50&tid=0&pn=\(videoNowPage)&keyword=&order=pubdate&platform=web&web_location=1550101&order_avoided=true&dm_img_list=[]&dm_img_str=V2ViR0wgMS4wIChPcGVuR0wgRVMgMi4wIENocm9taXVtKQ&dm_cover_img_str=VjNEIDQuMkJyb2FkY2".base64Encoded()) { signed in
biliWbiSign(paramEncoded: "mid=\(uid)&ps=50&pn=\(videoNowPage)".base64Encoded()) { signed in
if let signed {
debugPrint(signed)
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/space/wbi/arc/search?\(signed)", headers: headers) { respJson, isSuccess in
Expand Down Expand Up @@ -632,7 +633,7 @@ struct UserDetailView: View {
}

struct ModifyUserRelation: Codable {
let fid: Int
let fid: Int64
let act: Int
var re_src: Int = 11
let csrf: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Alamofire
import SwiftyJSON

struct bMessageSendView: View {
var uid: Int
var uid: Int64
var username: String
@AppStorage("DedeUserID") var dedeUserID = ""
@AppStorage("DedeUserID__ckMd5") var dedeUserID__ckMd5 = ""
Expand Down Expand Up @@ -117,7 +117,7 @@ struct bMessageSendView: View {
// })
// .frame(width: 50, height: 30)
TextField("私信", text: $sendTextCache)
.opacity(0.0100000002421438702673861521)
.opacity(0.0100000002421438702673861521) // MARK: You can find the limit here. If opacity lower than this value, this control won't be loaded.
.background {
ZStack {
Capsule()
Expand All @@ -137,7 +137,7 @@ struct bMessageSendView: View {
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata);"
]
AF.request("https://api.vc.bilibili.com/web_im/v1/web_im/send_msg", method: .post, parameters: ["msg[sender_uid]": Int(dedeUserID)!, "msg[receiver_id]": uid, "msg[receiver_type]": 1, "msg[msg_type]": 1, "msg[dev_id]": "372778FD-E359-461D-86A3-EA2BCC6FF52A", "msg[timestamp]": Date.now.timeStamp, "msg[content]": "{\"content\":\"\(sendTextCache)\"}", "csrf": biliJct], headers: headers).response { response in
AF.request("https://api.vc.bilibili.com/web_im/v1/web_im/send_msg", method: .post, parameters: ["msg[sender_uid]": Int64(dedeUserID)!, "msg[receiver_id]": uid, "msg[receiver_type]": 1, "msg[msg_type]": 1, "msg[dev_id]": "372778FD-E359-461D-86A3-EA2BCC6FF52A", "msg[timestamp]": Date.now.timeStamp, "msg[content]": "{\"content\":\"\(sendTextCache)\"}", "csrf": biliJct], headers: headers).response { response in
messages.append(["SenderID": dedeUserID, "Text": sendTextCache, "Timestamp": String(Date.now.timeStamp)])
sendTextCache = ""
debugPrint(response)
Expand Down

0 comments on commit ee0e522

Please sign in to comment.