Explorar el Código

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

zenghong hace 1 semana
padre
commit
5f91774e63

+ 3 - 0
PDF Office/PDF Master/Class/AIInfo/AIConfigWindowController/AIConfigWindowController.swift

@@ -736,6 +736,9 @@ import Cocoa
                             var charCount: Int = 0
                             if infoDict["charCount"] != nil {
                                 charCount = (infoDict["charCount"] ?? "0") as! Int
+                                if credit == 0 {
+                                    credit = charCount/10000 + 1
+                                }
                             }
                             
                             translateTipWC.creditValid = true

+ 3 - 0
PDF Office/PDF Master/Class/AIInfo/AIConfigWindowController/AINewConfigWindowController.swift

@@ -596,6 +596,9 @@ protocol AIConfigWindowDelegate: AnyObject {
                         var charCount: Int = 0
                         if infoDict["charCount"] != nil {
                             charCount = (infoDict["charCount"] ?? "0") as! Int
+                            if credit == 0 {
+                                credit = charCount/10000 + 1
+                            }
                         }
                         
                         chatModel.creditsValid = true

+ 1 - 1
PDF Office/PDF Master/Class/AIInfo/AIConfigWindowController/AINewConfigWindowController.xib

@@ -18,7 +18,7 @@
             <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES" fullSizeContentView="YES"/>
             <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
             <rect key="contentRect" x="196" y="240" width="276" height="739"/>
-            <rect key="screenRect" x="0.0" y="0.0" width="1800" height="1125"/>
+            <rect key="screenRect" x="0.0" y="0.0" width="1920" height="1055"/>
             <value key="minSize" type="size" width="276" height="739"/>
             <value key="maxSize" type="size" width="276" height="2739"/>
             <view key="contentView" id="se5-gp-TjO">

+ 122 - 126
PDF Office/PDF Master/Class/AIInfo/KMAIRequestServerManager.swift

@@ -59,21 +59,9 @@ class ResultWrapper: NSObject {
         if state == .rewrite || state == .correctTypos {  //重写 && 纠错
             aiRewriting(content: content, state: state, complete: complete)
         } else if state == .uploadTranslate || state == .fileTranslate {    // 上传文件 || 文件翻译
-//            let aiInfo: AIInfo = AIInfoManager.default().aiInfo
-//            if aiInfo.totalToken - aiInfo.usedTimes > 1 {
-//                aiTranslationFileUpload(file: content, complete: { [weak self] wrapper in
-//                    let success: Bool = wrapper.success
-//                    let fileKey = wrapper.content
-//                    if success {
-//                        let fileData = wrapper.result
-//                        complete(wrapper)
-//     
-//                    } else {
-//                        complete(wrapper)
-//                    }
-//                })
-//            } else {
-                memberAITranslationFileUpload(file: content, complete: { [weak self] wrapper in
+            let aiInfo: AIInfo = AIInfoManager.default().aiInfo
+            if aiInfo.totalToken - aiInfo.usedTimes > 1 {
+                aiTranslationFileUpload(file: content, complete: { [weak self] wrapper in
                     let success: Bool = wrapper.success
                     let fileKey = wrapper.content
                     if success {
@@ -83,9 +71,20 @@ class ResultWrapper: NSObject {
                     } else {
                         complete(wrapper)
                     }
-                })  
-//        }
-            
+                })
+            } else {
+                memberAITranslationFileUpload(file: content, complete: { [weak self] wrapper in
+                    let success: Bool = wrapper.success
+                    let fileKey = wrapper.content
+                    if success {
+                        let fileData = wrapper.result
+                        complete(wrapper)
+                        
+                    } else {
+                        complete(wrapper)
+                    }
+                })
+            }
         } else if state == .textTranslate { // 文本翻译
             let aiInfo: AIInfo = AIInfoManager.default().aiInfo
             if aiInfo.totalToken - aiInfo.usedTimes > 1 {
@@ -305,9 +304,9 @@ class ResultWrapper: NSObject {
         
         let urlString = AIInfoConfig().memberAIActionURL + "/member-system-website/v1/translate/fileUpload"
         let fileData = FileManager.default.contents(atPath: file)
-        let params: [String: Any] = ["file": fileData,
-                                     "calculate": "1"]
- 
+        let params: [String: Any] = ["file" : fileData,
+                                     "calculate" : "1"]
+  
         KMAIRequestServer.requestServer.uploadFile(urlString: urlString, params: params) { formData in
             let fileURL = URL(fileURLWithPath: file)
             try? formData.appendPart(withFileURL: fileURL, name: "file", fileName: fileURL.lastPathComponent, mimeType: "application/octet-stream")
@@ -316,84 +315,19 @@ class ResultWrapper: NSObject {
             requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
         } completion: { task, responseObject, error in
             if responseObject != nil {
-                let data: NSDictionary = responseObject!["data"] as? NSDictionary ?? [:]
-                var code: String = responseObject!["code"] as? String ?? "06005"
-                if code == "06005" {
-                    let tempCode: Int = responseObject!["code"] as? Int ?? 0
-                    if tempCode == 501 {
-                        code = "501"
-                    }
-                }
-                
-                let message: String = responseObject!["message"] as? String ?? "unknown error"
-                let error = NSError(domain: message, code: Int(code)!)
- 
-                if Int(code)! == 200 {
+                let data: NSDictionary = responseObject as? NSDictionary ?? [:]
+                if data.count > 0 {
                     let wrapper = ResultWrapper(success: true, resultData: data)
-                    wrapper.content = data["fileKey"] as! String
-                    complete(wrapper)
-                } else {
-                    let wrapper = ResultWrapper(success: false, resultData: data)
-                    if Int(code)! == 501 {
-                        wrapper.content = "501"
-                    } else {
-                        wrapper.content = message
+                    if let value = data["fileKey"] {
+                        wrapper.content = value as! String
                     }
                     complete(wrapper)
-                }
-            } else {
-                 complete(ResultWrapper(success: false, content: "unknown error"))
-            }
-        }
-    }
-    
-    private func aiMemberTranslationFileUpload(file: String, complete: @escaping KMRequestServerComplete) {
-        let token: String = KMMemberInfo.shared.access_token
-        if token == "" {
-            return
-        }
-        
-        let infoDictionary = Bundle .main.infoDictionary!
-        let urlString = AIInfoConfig().aiActionURL + "/api/AI/uploadTranslate"
-        let fileData = FileManager.default.contents(atPath: file)
-        let params: [String: Any] = ["file": fileData,
-                                     "uuid": uuid(),
-                                     "platform": platform(),
-                                     "app_name": app_name(),
-                                     "calculate":"1"]
-        KMAIRequestServer.requestServer.uploadFile(urlString: urlString, params: params) { formData in
-            let fileURL = URL(fileURLWithPath: file)
-            try? formData.appendPart(withFileURL: fileURL, name: "file", fileName: fileURL.lastPathComponent, mimeType: "application/octet-stream")
-        } requestSerializer: { requestSerializer in
-            requestSerializer.setValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
-        } completion: { task, responseObject, error in
-            if responseObject != nil {
-                let data: NSDictionary = responseObject!["data"] as? NSDictionary ?? [:]
-                var code: String = responseObject!["code"] as? String ?? "06005"
-                if code == "06005" {
-                    let tempCode: Int = responseObject!["code"] as? Int ?? 0
-                    if tempCode == 501 {
-                        code = "501"
-                    }
-                }
-                
-                let message: String = responseObject!["message"] as? String ?? "unknown error"
-                let error = NSError(domain: message, code: Int(code)!)
- 
-                if Int(code)! == 200 {
-                    let wrapper = ResultWrapper(success: true, resultData: data)
-                    wrapper.content = data["fileKey"] as! String
-                    complete(wrapper)
                 } else {
-                    let wrapper = ResultWrapper(success: false, resultData: data)
-                    if Int(code)! == 501 {
-                        wrapper.content = "501"
-                    } else {
-                        wrapper.content = message
-                    }
-                    complete(wrapper)
+                    let error = NSError(domain: "unknown error", code: 404)
+                     complete(ResultWrapper(success: false, content: "unknown error"))
                 }
             } else {
+                let error = NSError(domain: "unknown error", code: 404)
                  complete(ResultWrapper(success: false, content: "unknown error"))
             }
         }
@@ -406,26 +340,81 @@ class ResultWrapper: NSObject {
      @param to 结束语言
      */
     func aiTranslationFileTranslateHandle(fileKey: String, from: String, to: String, complete: @escaping KMRequestServerComplete) {
-        
-        let infoDictionary = Bundle .main.infoDictionary!
-        let urlString = AIInfoConfig().aiActionURL + "/api/AI/fileTranslate"
+        let aiInfo: AIInfo = AIInfoManager.default().aiInfo
+        if aiInfo.totalToken - aiInfo.usedTimes > 1 {
+            let infoDictionary = Bundle .main.infoDictionary!
+            let urlString = AIInfoConfig().aiActionURL + "/api/AI/fileTranslate"
+            
+            let paraDict = ["fileKey": fileKey,
+                            "from": languageAbbreviation(from),
+                            "to": languageAbbreviation(to),
+                            "uuid": uuid(),
+                            "platform": platform(),
+                            "app_name": app_name()]
+            var postData  = try! JSONSerialization.data(withJSONObject: paraDict)
+            
+            
+            var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
+            request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
+            request.addValue("application/json", forHTTPHeaderField: "Content-Type")
+            
+            request.httpMethod = "POST"
+            request.httpBody = postData
+            
+            let task = URLSession.shared.dataTask(with: request) { data, response, error in
+                guard let data = data else {
+                    print(String(describing: error))
+                    return
+                }
+                let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary ?? [:]
+                if jsonObject != nil {
+                    let data1: NSDictionary = jsonObject!["data"] as? NSDictionary ?? [:]
+                    let code: String = jsonObject!["code"] as? String ?? "06005"
+                    let message: String = jsonObject!["message"] as? String ?? "unknown error"
+                    let error = NSError(domain: message, code: Int(code)!)
+                    
+                    if Int(code)! == 200 {
+                        let fileUrl = data1["fileUrl"]
+                        let downFileUrl = data1["downFileUrl"]
+                        let ossDownUrl = data1["ossDownUrl"]
+                        let fileName = data1["fileName"]
+                        let downFileName = data1["downFileName"]
+                        let fromStr = data1["from"]
+                        let toStr = data1["to"]
+                        
+                        self.downFileName = downFileName as! String
+                        complete(ResultWrapper(success: true, content: ossDownUrl as! String))
+                    } else {
+                        complete(ResultWrapper(success: false, content: message))
+                    }
+                } else {
+                    complete(ResultWrapper(success: false, content: "unknown error"))
+                }
+            }
+            task.resume()
+        } else {
+            memberAITranslationFileTranslateHandle(fileKey: fileKey, from: from, to: to, complete: complete)
+        }
+    }
+    
+    func memberAITranslationFileTranslateHandle(fileKey: String, from: String, to: String, complete: @escaping KMRequestServerComplete) {
+        let token: String = KMMemberInfo.shared.access_token
+
+        let urlString = AIInfoConfig().memberAIActionURL + "/member-system-website/v1/translate/fileTranslateHandle"
 
         let paraDict = ["fileKey": fileKey,
                         "from": languageAbbreviation(from),
-                        "to": languageAbbreviation(to),
-                        "uuid": uuid(),
-                        "platform": platform(),
-                        "app_name": app_name()]
-        var postData  = try! JSONSerialization.data(withJSONObject: paraDict)
-
-        
+                        "to": languageAbbreviation(to)]
+        let postData  = try! JSONSerialization.data(withJSONObject: paraDict)
+ 
         var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
-        request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
         request.addValue("application/json", forHTTPHeaderField: "Content-Type")
-
+        
+        request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
+        request.addValue("Bearer " + token, forHTTPHeaderField: "Authorization")
         request.httpMethod = "POST"
         request.httpBody = postData
-
+        
         let task = URLSession.shared.dataTask(with: request) { data, response, error in
            guard let data = data else {
                print(String(describing: error))
@@ -433,27 +422,35 @@ class ResultWrapper: NSObject {
            }
             let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary ?? [:]
             if jsonObject != nil {
-                let data1: NSDictionary = jsonObject!["data"] as? NSDictionary ?? [:]
-                let code: String = jsonObject!["code"] as? String ?? "06005"
-                let message: String = jsonObject!["message"] as? String ?? "unknown error"
-                let error = NSError(domain: message, code: Int(code)!)
- 
-                if Int(code)! == 200 {
-                    let fileUrl = data1["fileUrl"]
-                    let downFileUrl = data1["downFileUrl"]
-                    let ossDownUrl = data1["ossDownUrl"]
-                    let fileName = data1["fileName"]
-                    let downFileName = data1["downFileName"]
-                    let fromStr = data1["from"]
-                    let toStr = data1["to"]
-                    
-                    self.downFileName = downFileName as! String
-                     complete(ResultWrapper(success: true, content: ossDownUrl as! String))
+                let codeStr: String = jsonObject!["code"] as! String
+                var code: Int = 0
+                if let numCode = Int(codeStr) {
+                    code = numCode
+                }
+                var result_bool: Bool = true
+                var message: String = ""
+                
+                let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
+                if code == 200 {
+                    if jsonObject!["data"] != nil {
+                        let dataDic = jsonObject!["data"] as? NSDictionary ?? [:]
+                        
+                        let fileUrl = dataDic["fileUrl"]
+                        let downFileUrl = dataDic["downFileUrl"]
+                        let ossDownUrl = dataDic["ossDownUrl"]
+                        let fileName = dataDic["fileName"]
+                        let downFileName = dataDic["downFileName"]
+                        let fromStr = dataDic["from"]
+                        let toStr = dataDic["to"]
+                        
+                        self.downFileName = downFileName as! String
+                        complete(ResultWrapper(success: true, content: ossDownUrl as! String))
+                    }
                 } else {
-                    complete(ResultWrapper(success: false, content: message))
+                    complete(ResultWrapper(success: false, content: ""))
                 }
             } else {
-                complete(ResultWrapper(success: false, content: "unknown error"))
+                complete(ResultWrapper(success: false, content: ""))
             }
         }
         task.resume()
@@ -905,7 +902,6 @@ class KMAIRequestServer {
             }
         }
         task.resume()
-        
-        
+         
     }
 }

+ 5 - 5
PDF Office/PDF Master/Class/Home/WindowController/KMAITranslationConfirmWindowController.xib

@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22155" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22155"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
-        <customObject id="-2" userLabel="File's Owner" customClass="KMAITranslationConfirmWindowController" customModule="PDF_Master" customModuleProvider="target">
+        <customObject id="-2" userLabel="File's Owner" customClass="KMAITranslationConfirmWindowController" customModule="PDF_Reader_Pro" customModuleProvider="target">
             <connections>
                 <outlet property="cancelBox" destination="vyK-GF-45b" id="SmK-bv-L3Z"/>
                 <outlet property="cancelButton" destination="cGZ-Im-IxK" id="rmV-MT-RM5"/>
@@ -33,7 +33,7 @@
             <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
             <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
             <rect key="contentRect" x="196" y="240" width="628" height="334"/>
-            <rect key="screenRect" x="0.0" y="0.0" width="2560" height="1415"/>
+            <rect key="screenRect" x="0.0" y="0.0" width="1920" height="1055"/>
             <view key="contentView" id="se5-gp-TjO">
                 <rect key="frame" x="0.0" y="0.0" width="628" height="276"/>
                 <autoresizingMask key="autoresizingMask"/>
@@ -158,7 +158,7 @@
                     <customView translatesAutoresizingMaskIntoConstraints="NO" id="WyA-fZ-iqG">
                         <rect key="frame" x="16" y="64" width="596" height="162"/>
                         <subviews>
-                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="g0s-3J-B7Z" customClass="KMCustomPDFView" customModule="PDF_Master" customModuleProvider="target">
+                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="g0s-3J-B7Z" customClass="KMCustomPDFView" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                 <rect key="frame" x="0.0" y="22" width="106" height="140"/>
                                 <constraints>
                                     <constraint firstAttribute="width" constant="106" id="bJf-WD-7Mo"/>

+ 8 - 8
PDF Office/PDF Master/MemberCenter/Model/KMMemberInfo.swift

@@ -542,17 +542,17 @@ import Cocoa
                                 self.userScenarioType == .lite_type6 ||
                                 self.userScenarioType == .lite_type10 ||
                                 self.userScenarioType == .lite_type12 ||
-                                userScenarioType == .pro_type2 ||
-                                userScenarioType == .pro_type5{
+                                self.userScenarioType == .pro_type2 ||
+                                self.userScenarioType == .pro_type5{
                         
-                    } else if userScenarioType == .pro_type1 ||
-                                userScenarioType == .pro_type3 ||
-                                userScenarioType == .pro_type4 {
+                    } else if self.userScenarioType == .pro_type1 ||
+                                self.userScenarioType == .pro_type3 ||
+                                self.userScenarioType == .pro_type4 {
                         KMProductCompareWC.shared.orientation = true
-                        if userScenarioType == .pro_type1 ||
-                            userScenarioType == .pro_type4 {
+                        if self.userScenarioType == .pro_type1 ||
+                            self.userScenarioType == .pro_type4 {
                             KMProductCompareWC.shared.orientationType = .pro_Advanced
-                        } else if userScenarioType == .pro_type3 {
+                        } else if self.userScenarioType == .pro_type3 {
                             KMProductCompareWC.shared.orientationType = .pro_Base
                         }
                         KMProductCompareWC.shared.showWindow(nil)

+ 1 - 1
PDF Office/PDF Master/MemberCenter/View/KMEnterVerificationCodeView.swift

@@ -79,7 +79,7 @@ class KMEnterVerificationCodeView: KMBaseXibView {
             if self.viewModel.sendBoxSelect { return }
             if downEntered {
                 self.sendBox.fillColor = NSColor(named: "273C62_0.4") ?? NSColor.blue
-                viewModel.countDown(type: .reset)
+                self.viewModel.countDown(type: .reset)
             }
         }
     }

+ 1 - 1
PDF Office/PDF Master/MemberCenter/View/KMSignUpView.swift

@@ -197,7 +197,7 @@ class KMSignUpView: KMBaseXibView {
             if self.viewModel.sendBoxSelect { return }
             if downEntered {
                 self.sendBox.fillColor = NSColor(named: "273C62_0.4") ?? NSColor.blue
-                viewModel.countDown(type: .login)
+                self.viewModel.countDown(type: .login)
             }
         }
     }

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

@@ -113,7 +113,7 @@ class KMSignUpViewModel: ObservableObject {
                     // 倒计时结束,停止定时器
                     self.timer?.cancel()
                     self.sendContent = NSLocalizedString("Resend", tableName: "MemberCenterLocalizable", comment: "")
-                    sendBoxSelect = false
+                    self.sendBoxSelect = false
                 }
             }
     }
@@ -273,7 +273,7 @@ class KMSignUpViewModel: ObservableObject {
                         alert.runModal()
                         return
                     }
-                    KMMemberCenterManager.manager.getUserDeviceList(email: email) { [weak self] success, result in
+                    KMMemberCenterManager.manager.getUserDeviceList(email: self.email) { [weak self] success, result in
                         guard self != nil else { return }
                         if success {
                             KMMemberCenterWindowController.shared.showWindow(nil)
@@ -288,8 +288,8 @@ class KMSignUpViewModel: ObservableObject {
                     let response = alert.runModal()
                     if response == .alertFirstButtonReturn {
                         if(resultDict.code == 317) {
-                            signUpState = .verificationCode
-                            countDown(type: .login)
+                            self.signUpState = .verificationCode
+                            self.countDown(type: .login)
                         } else {
                             
                         }

+ 1 - 1
PDF Office/PDF Master/MemberCenter/WindowsController/DMG/KMOpenDMGPopupBootWC.swift

@@ -93,7 +93,7 @@ class KMOpenDMGPopupBootWC: NSWindowController {
         freeBox.downCallback = { [weak self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
             guard let self = self else { return }
             if downEntered {
-                viewModel.getVipFree()
+                self.viewModel.getVipFree()
                 self.window?.close()
             }
         }

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

@@ -114,7 +114,7 @@ class KMCloseVerificationWC: NSWindowController {
             if self.signUpModel.sendBoxSelect { return }
             if downEntered {
                 self.sendBox.fillColor = NSColor(named: "273C62_0.4") ?? NSColor.blue
-                signUpModel.countDown(type: .logout)
+                self.signUpModel.countDown(type: .logout)
             }
         }
 

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

@@ -216,8 +216,6 @@ class KMProductCompareWC: NSWindowController {
         } else {
             model.getCurrentComparisonTableType()
         }
-        languageLocalized()
-        initializeUI()
 
         value1InfoLabel.stringValue = NSLocalizedString("6-Month Plan", comment: "")
         value1InfoLabel.font = NSFont.UbuntuMediumFontWithSize(16)
@@ -306,6 +304,8 @@ class KMProductCompareWC: NSWindowController {
 
     @objc override func showWindow(_ sender: Any?) {
         super.showWindow(sender)
+        languageLocalized()
+        initializeUI()
         reloadData()
         if model.isShowSale {
             showDiscountToSaveWindow()