Bladeren bron

Merge branch 'develop_PDFReaderPro_V4.7.0' of git.kdan.cc:Mac_PDF/PDF_Office into develop_PDFReaderPro_V4.7.0

tangchao 1 week geleden
bovenliggende
commit
5d3bcf9881

+ 1 - 1
PDF Office/PDF Master/AppDelegate.swift

@@ -120,7 +120,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, iRateDelegate{
         if token is String {
             if (token as! String).count > 0 {
                 KMMemberInfo.shared.access_token = token as! String
-                KMUserInfoVCModel().refreshUserInfo { success, msg in
+                KMUserInfoVCModel().refreshUserInfo { success, msg,dic  in
                     if success {
                         KMMemberInfo.shared.isLogin = true
                         NotificationCenter.default.post(name: NSNotification.Name(rawValue: "MemberCenterLoginSuccess"), object: nil)

+ 2 - 2
PDF Office/PDF Master/Class/AIInfo/AIConfigWindowController/Views/AIHeaderView/AIHeaderView.swift

@@ -56,7 +56,7 @@ class AIHeaderView: NSView, NibLoadable {
             
         }
         if(KMMemberInfo.shared.isLogin == true) {
-            KMUserInfoViewController.refreshTokenUserInfo {[weak self] success in
+            KMUserInfoViewController.refreshTokenUserInfo {[weak self] success, resDic in
                 if(success == true) {
                     self?.enterAIInfo(sender)
                 }
@@ -68,7 +68,7 @@ class AIHeaderView: NSView, NibLoadable {
     
     func enterAIInfo(_ sender: NSButton) {
         
-        KMUserInfoVCModel().refreshUserInfo { success, msg in
+        KMUserInfoVCModel().refreshUserInfo { success, msg ,res in
             NotificationCenter.default.post(name: NSNotification.Name(rawValue: kDeviceAIStatusChangeNotification), object: nil)
          }
         

+ 58 - 29
PDF Office/PDF Master/Class/AIInfo/KMAIRequestServerManager.swift

@@ -518,13 +518,25 @@ class ResultWrapper: NSObject {
     }
     
     private func aiMemberTranslationTextTrans(q: String, from: String, to: String, complete: @escaping KMRequestServerComplete) {
-        let token: String = KMMemberInfo.shared.access_token
-        if token == "" {
-            return
+        if(KMMemberInfo.shared.isLogin == true) {
+            KMUserInfoViewController.refreshTokenUserInfo {[weak self] success, resDic in
+                if(success == true) {
+                    self?.aiMemberTranslationTextTransReq(q: q, from: from, to: to, complete: complete)
+                } else {
+                    let code = resDic?.code ?? 200
+                    if(code == 304) {
+                        KMLoginWindowsController.shared.showWindow(nil)
+                    }
+                }
+            }
+            
         }
-        
+    }
+    
+    func aiMemberTranslationTextTransReq(q: String, from: String, to: String, complete: @escaping KMRequestServerComplete) {
         let urlString = AIInfoConfig().memberAIActionURL + "/member-system-website/v1/translate/textTrans"
-        
+        let token: String = KMMemberInfo.shared.access_token
+
         var escapedString = q
         escapedString = String(data: escapedString.data(using: .utf8)!, encoding: .utf8)!
         let paraDict = ["text":escapedString,
@@ -594,37 +606,54 @@ class ResultWrapper: NSObject {
                 }
             }
         } else {
-            let token: String = KMMemberInfo.shared.access_token
-            if token == "" {
-                return
-            }
-            var urlString = AIInfoConfig().memberAIActionURL + "/member-system-website/api/rewrite"
-            if state == .correctTypos {
-                urlString = AIInfoConfig().memberAIActionURL + "/member-system-website/api/correct-typos"
-            }
-            let params: [String: Any] = ["content": content]
-            
-            KMAIRequestServer.requestServer.aiMemberRewriting(urlString: urlString, params: params) { formData in
-                
-            } requestSerializer: { requestSerializer in
-                requestSerializer.setValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
-                requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
-            } completion: { task, responseObject, error in
-                if responseObject is KMMemberCenterResult {
-                    let resultObjct = responseObject as! KMMemberCenterResult
-                    let code = resultObjct.code
-                    let message: String = resultObjct.msg ?? ""
-                    if code == 200 {
-                        complete(ResultWrapper(success: true, content: message))
+            if(KMMemberInfo.shared.isLogin == true) {
+                KMUserInfoViewController.refreshTokenUserInfo {[weak self] success, resDic in
+                    if(success == true) {
+                        self?.aiMemberRewriting(content: content, state: state, complete: complete)
                     } else {
-                        complete(ResultWrapper(success: false, content: message))
+                        let code = resDic?.code ?? 200
+                        if(code == 304) {
+                            KMLoginWindowsController.shared.showWindow(nil)
+                        }
                     }
+                }
+                
+            }
+        }
+    }
+    
+    func aiMemberRewriting(content: String, state: KMAIRewritingState, complete: @escaping KMRequestServerComplete) {
+        let token: String = KMMemberInfo.shared.access_token
+        if token == "" {
+            return
+        }
+        var urlString = AIInfoConfig().memberAIActionURL + "/member-system-website/api/rewrite"
+        if state == .correctTypos {
+            urlString = AIInfoConfig().memberAIActionURL + "/member-system-website/api/correct-typos"
+        }
+        let params: [String: Any] = ["content": content]
+        
+        KMAIRequestServer.requestServer.aiMemberRewriting(urlString: urlString, params: params) { formData in
+            
+        } requestSerializer: { requestSerializer in
+            requestSerializer.setValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
+            requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
+        } completion: { task, responseObject, error in
+            if responseObject is KMMemberCenterResult {
+                let resultObjct = responseObject as! KMMemberCenterResult
+                let code = resultObjct.code
+                let message: String = resultObjct.msg ?? ""
+                if code == 200 {
+                    complete(ResultWrapper(success: true, content: message))
                 } else {
-                    complete(ResultWrapper(success: false, content: "unknown error"))
+                    complete(ResultWrapper(success: false, content: message))
                 }
+            } else {
+                complete(ResultWrapper(success: false, content: "unknown error"))
             }
         }
     }
+
     
     /**
      @abstract 提取摘要

+ 6 - 1
PDF Office/PDF Master/Class/Purchase/DMG/Verification/KMVerificationMessageViewController.m

@@ -545,7 +545,7 @@ NSPopoverDelegate>
 }
 
 - (IBAction)personalCenterAction:(NSButton *)sender {
-    [KMUserInfoViewController refreshTokenUserInfoWithCallback:^(BOOL success) {
+    [KMUserInfoViewController refreshTokenUserInfoWithCallback:^(BOOL success,KMMemberCenterResult*resDic) {
         if(success) {
             if([KMMemberInfo shared].isLogin == YES) {
                 // 用户头像点击事件
@@ -557,6 +557,11 @@ NSPopoverDelegate>
                 item.view = userInfo.view;
                 [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
             }
+        } else {
+            NSInteger code = resDic.code;
+            if(code == 304) {
+                [[KMLoginWindowsController shared] showWindow:nil];
+            }
         }
     }];
   

+ 2 - 1
PDF Office/PDF Master/MemberCenter/Model/KMMemberCenterResult.swift

@@ -7,9 +7,10 @@
 
 import Cocoa
 
+@objcMembers
 class KMMemberCenterResult: NSObject {
     
-    var code                : Int?
+    var code                : Int = 0
     var msg                 : String?
     var result              : Bool?
         

+ 5 - 5
PDF Office/PDF Master/MemberCenter/ViewController/KMUserInfoViewController.swift

@@ -106,7 +106,7 @@ class KMUserInfoViewController: NSViewController {
         KMPrint("KMUserInfoViewController deinit.")
     }
     
-   @objc class func refreshTokenUserInfo(callback: ((Bool)->Void)?) -> Void {
+   @objc class func refreshTokenUserInfo(callback: ((Bool,KMMemberCenterResult?)->Void)?) -> Void {
         if KMMemberCenterManager.manager.isConnectionAvailable() == false {
             let alert = NSAlert()
             alert.alertStyle = .critical
@@ -114,13 +114,13 @@ class KMUserInfoViewController: NSViewController {
             alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
             alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
             alert.runModal()
-            
-            callback?(false)
+            let res = KMMemberCenterResult(code: 500, msg: "", result: false)
+            callback?(false,res)
             return
         }
         
-        KMUserInfoVCModel().refreshUserInfo(networkAlert: false) { success, msg in
-            callback?(success)
+       KMUserInfoVCModel().refreshUserInfo(networkAlert: false) { success, msg,resDic  in
+            callback?(success,resDic)
             if success {
                 KMMemberInfo.shared.isLogin = true
                 NotificationCenter.default.post(name: NSNotification.Name(rawValue: "MemberCenterLoginSuccess"), object: nil)

+ 1 - 1
PDF Office/PDF Master/MemberCenter/ViewModel/KMSignUpViewModel.swift

@@ -184,7 +184,7 @@ class KMSignUpViewModel: ObservableObject {
             return
         }
         
-        KMUserInfoVCModel().refreshUserInfo(networkAlert: false) { success, msg in
+        KMUserInfoVCModel().refreshUserInfo(networkAlert: false) { success, msg,dic  in
             callback?(success)
             if success {
                 KMMemberInfo.shared.isLogin = true

+ 4 - 4
PDF Office/PDF Master/MemberCenter/ViewModel/KMUserInfoVCModel.swift

@@ -13,7 +13,7 @@ import Combine
     case advancedYearMonthPlan      // 高级版年订阅
 }
 
-typealias UserInfoComplete = (_ success: Bool,_ msg: String) -> Void
+typealias UserInfoComplete = (_ success: Bool,_ msg: String,_ resDic:KMMemberCenterResult?) -> Void
 
 @objcMembers
 class KMUserInfoVCModel: ObservableObject {
@@ -42,9 +42,9 @@ class KMUserInfoVCModel: ObservableObject {
                 let userInfo = resultDict.userInfo
                 guard let userInfo = resultDict.userInfo else { return }
                 KMMemberInfo.shared.memberUserInfo(model: userInfo)
-                complete(true, "")
+                complete(true, "",resultDict)
             } else {
-                complete(false, "")
+                complete(false, "",resultDict)
                 if(code == 304) {
                     KMMemberInfo.shared.clearMemberInfoCache()
                     KMMemberInfo.shared.isLogin = false
@@ -182,7 +182,7 @@ class KMUserInfoVCModel: ObservableObject {
                 let resultDict = result as KMMemberCenterResult
                 let msg = resultDict.msg
                 if success {
-                    self.refreshUserInfo { success, msg in
+                    self.refreshUserInfo { success, msg,resdic  in
                         KMMemberPromptWC.shared.showWindow(nil)
                         KMMemberPromptWC.shared.tipType = .cancelSignout
                     }

+ 1 - 1
PDF Office/PDF Master/MemberCenter/WindowsController/KMCloseApplyWC.swift

@@ -70,7 +70,7 @@ class KMCloseApplyWC: NSWindowController {
     
     
     @IBAction func yesButtonAction(_ sender: NSButton) {
-        KMUserInfoVCModel().refreshUserInfo { success, msg in
+        KMUserInfoVCModel().refreshUserInfo { success, msg,dic  in
             self.window?.close()
         }
     }

+ 1 - 1
PDF Office/PDF Master/MemberCenter/WindowsController/KMProductCompareWC.swift

@@ -1134,7 +1134,7 @@ class KMProductCompareWC: NSWindowController {
         reloadData()
         if KMMemberInfo.shared.isLogin {
             model.appStoreEquityVerification(notification) { success, msg in
-                KMUserInfoVCModel().refreshUserInfo { success, msg in
+                KMUserInfoVCModel().refreshUserInfo { success, msg,dic  in
                 }
             }
         }