Skip to content

Commit

Permalink
feat: Ban ID (#326)
Browse files Browse the repository at this point in the history
* Update FeedbackView.swift

* Update MeowBiliApp.swift

* Update FeedbackView.swift

* feat: Finish ban logic
  • Loading branch information
WindowsMEMZ authored Mar 21, 2024
1 parent 2147413 commit 9664811
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 24 deletions.
27 changes: 26 additions & 1 deletion MeowBili/Errors/FeedbackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ struct InAppFeedbackView: View {
return
}
isSending = true
#if os(watchOS)
let banId = WKInterfaceDevice.current().identifierForVendor?.uuidString ?? "nil"
#else
let banId = UIDevice.current.identifierForVendor?.uuidString ?? "nil"
#endif
let msgToSend = """
\(titleInput)
State:0
Expand All @@ -136,6 +141,8 @@ struct InAppFeedbackView: View {
Version:v\(Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String) Build \(Bundle.main.infoDictionary?["CFBundleVersion"] as! String)
Time:\(Date.now.timeIntervalSince1970)
Sender: User
BanID:\(banId)
BanUID:\(UserDefaults.standard.string(forKey: "DedeUserId") ?? "Empty")
"""
DarockKit.Network.shared.requestString("https://api.darock.top/feedback/submit/anony/喵哩喵哩/\(msgToSend.base64Encoded().replacingOccurrences(of: "/", with: "{slash}"))") { respStr, isSuccess in
if isSuccess {
Expand Down Expand Up @@ -167,7 +174,7 @@ struct InAppFeedbackView: View {
})
.disabled(isSending)
} footer: {
Text("Darock 会收集必要的诊断信息以便进行改进,信息不会关联到您个人。如果您不愿意被收集信息,请勿发送。")
Text("Darock 会收集必要的诊断信息以便进行改进。如果您不愿意被收集信息,请勿发送。")
}
}
}
Expand Down Expand Up @@ -321,6 +328,24 @@ struct InAppFeedbackView: View {
}
}

struct BannedTipView: View {
var body: some View {
ScrollView {
VStack {
Text("您已被 Darock 永久封禁且在设备上施行")
#if os(watchOS)
let banId = WKInterfaceDevice.current().identifierForVendor?.uuidString ?? "nil"
#else
let banId = UIDevice.current.identifierForVendor?.uuidString ?? "nil"
#endif
Text(banId)
Text(UserDefaults.standard.string(forKey: "DedeUserId") ?? "Empty")
Text("加群248036605查看群公告以申请解封")
}
}
}
}

struct FeedbackView_Previews: PreviewProvider {
static var previews: some View {
FeedbackView()
Expand Down
78 changes: 55 additions & 23 deletions MeowBili/MeowBiliApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ struct DarockBili_Watch_AppApp: App {
#else
@State var shouldShowAppName = false
#endif
// Banner
@State var isAccountBanned = false
var body: some SwiftUI.Scene {
WindowGroup {
if fileLockerPwd != "" {
Expand Down Expand Up @@ -206,7 +208,11 @@ struct DarockBili_Watch_AppApp: App {
ZStack {
#if !os(visionOS)
#if os(watchOS)
ContentView()
if !isAccountBanned {
ContentView()
} else {
BannedTipView()
}
VStack {
Spacer()
if #available(watchOS 10, *) {
Expand Down Expand Up @@ -248,28 +254,32 @@ struct DarockBili_Watch_AppApp: App {
ZStack {
// Hide NavigationLinks behind
NavigationLink("", isActive: $isUrlOpenVideoPresented, destination: { VideoDetailView(videoDetails: urlOpenVideoDetails) })
ContentView()
.onOpenURL { url in
let dec = url.absoluteString.urlDecoded()
let spd = dec.split(separator: "/").dropFirst()
debugPrint(spd)
switch spd[1] {
case "withvideodetail":
let kvs = dec.split(separator: "/", maxSplits: 1).dropFirst()[2].split(separator: "&") // e.g.: ["BV=xxx", "Title=xxx"]
urlOpenVideoDetails.removeAll()
for kv in kvs {
let kav = kv.split(separator: "=")
urlOpenVideoDetails.updateValue(String(kav[1]), forKey: String(kav[0]))
}
isUrlOpenVideoPresented = true
case "openbvid":
let bvid = spd[2]
urlOpenVideoDetails = ["Pic": "", "Title": "Loading...", "BV": String(bvid), "UP": "Loading...", "View": "1", "Danmaku": "1"]
isUrlOpenVideoPresented = true
default:
break
}
}
if !isAccountBanned {
ContentView()
} else {
BannedTipView()
}
}
}
.onOpenURL { url in
let dec = url.absoluteString.urlDecoded()
let spd = dec.split(separator: "/").dropFirst()
debugPrint(spd)
switch spd[1] {
case "withvideodetail":
let kvs = dec.split(separator: "/", maxSplits: 1).dropFirst()[2].split(separator: "&") // e.g.: ["BV=xxx", "Title=xxx"]
urlOpenVideoDetails.removeAll()
for kv in kvs {
let kav = kv.split(separator: "=")
urlOpenVideoDetails.updateValue(String(kav[1]), forKey: String(kav[0]))
}
isUrlOpenVideoPresented = true
case "openbvid":
let bvid = spd[2]
urlOpenVideoDetails = ["Pic": "", "Title": "Loading...", "BV": String(bvid), "UP": "Loading...", "View": "1", "Danmaku": "1"]
isUrlOpenVideoPresented = true
default:
break
}
}
if shouldShowAppName {
Expand Down Expand Up @@ -480,6 +490,28 @@ struct DarockBili_Watch_AppApp: App {
}
}
}

#if os(watchOS)
let banId = WKInterfaceDevice.current().identifierForVendor?.uuidString ?? "__DONOTBANTHISIDELSEALLUSERSWILLBEBANNED123456AABBCCDDEEFFGGDAROCKSTUDIOCOMMUNITY"
#else
let banId = UIDevice.current.identifierForVendor?.uuidString ?? "__DONOTBANTHISIDELSEALLUSERSWILLBEBANNED123456AABBCCDDEEFFGGDAROCKSTUDIOCOMMUNITY"
#endif
DarockKit.Network.shared.requestString("https://api.darock.top/banner/check/\(banId)") { respStr, isSuccess in
if isSuccess {
if respStr == "1" {
isAccountBanned = true
}
}
}
if let uid = UserDefaults.standard.string(forKey: "DedeUserId") {
DarockKit.Network.shared.requestString("https://api.darock.top/banner/check/\(uid)") { respStr, isSuccess in
if isSuccess {
if respStr == "1" {
isAccountBanned = true
}
}
}
}
@unknown default:
break
}
Expand Down

0 comments on commit 9664811

Please sign in to comment.