From 966481120085b59fff4ffe9a8fd52ceb713a2dc6 Mon Sep 17 00:00:00 2001 From: Mark Chan <45706356+WindowsMEMZ@users.noreply.github.com> Date: Thu, 21 Mar 2024 21:18:49 +0800 Subject: [PATCH] feat: Ban ID (#326) * Update FeedbackView.swift * Update MeowBiliApp.swift * Update FeedbackView.swift * feat: Finish ban logic --- MeowBili/Errors/FeedbackView.swift | 27 ++++++++++- MeowBili/MeowBiliApp.swift | 78 +++++++++++++++++++++--------- 2 files changed, 81 insertions(+), 24 deletions(-) diff --git a/MeowBili/Errors/FeedbackView.swift b/MeowBili/Errors/FeedbackView.swift index a8aa26d9f..401b28eb3 100644 --- a/MeowBili/Errors/FeedbackView.swift +++ b/MeowBili/Errors/FeedbackView.swift @@ -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 @@ -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 { @@ -167,7 +174,7 @@ struct InAppFeedbackView: View { }) .disabled(isSending) } footer: { - Text("Darock 会收集必要的诊断信息以便进行改进,信息不会关联到您个人。如果您不愿意被收集信息,请勿发送。") + Text("Darock 会收集必要的诊断信息以便进行改进。如果您不愿意被收集信息,请勿发送。") } } } @@ -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() diff --git a/MeowBili/MeowBiliApp.swift b/MeowBili/MeowBiliApp.swift index 95ef48524..803fa3503 100644 --- a/MeowBili/MeowBiliApp.swift +++ b/MeowBili/MeowBiliApp.swift @@ -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 != "" { @@ -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, *) { @@ -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 { @@ -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 }