Parcourir la source

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

zenghong il y a 1 semaine
Parent
commit
f7cf913731

+ 5 - 7
PDF Office/PDF Master/Class/AIInfo/AIInfoConfig.swift

@@ -42,13 +42,11 @@ import Foundation
 class AIInfoConfig: NSObject {
     var aiActionURL: String {
         get {
-//            #if DEBUG
-//            return kVerificationServer
-//            #else
-//            //正式服务器
-//            return "https://store.pdfreaderpro.com"
-//            #endif
-            return "http://139.196.160.101:8081"
+            return kVerificationServer
         }
     }
+    
+    var memberAIActionURL: String {
+        return "http://139.196.160.101:8081"
+    }
 }

+ 2 - 11
PDF Office/PDF Master/Class/AIInfo/AIUserInfoController/AIUserInfoController.swift

@@ -234,18 +234,9 @@ import Cocoa
     
     func updateCreditsViewInfo() -> Void {
         let aiInfo: AIInfo = AIInfoManager.default().aiInfo
-        if aiInfo.infoDict.keys.count == 0 {
-            return
-        }
+
         self.validCreditLabel.stringValue = String(format: "%d", aiInfo.totalToken-aiInfo.usedTimes + Int32(KMMemberInfo.shared.aiPoint))
-        
-        let leftDays = String(format: "%ld", aiInfo.remainingDays)
-        
-        let dateFormatter = DateFormatter.init()
-        dateFormatter.dateFormat = "yyyy.MM.dd"
-        let startDateStr = dateFormatter.string(from: aiInfo.startDate)
-        let endDateStr = dateFormatter.string(from: aiInfo.endDate)
-        
+         
         self.emptyContendBox.isHidden = true
         self.emptyShowAIBtn.isHidden = true
         self.creditsContendBox.isHidden = true

+ 21 - 72
PDF Office/PDF Master/Class/AIInfo/KMAIRequestServerManager.swift

@@ -12,20 +12,9 @@ import AFNetworking
 class ResultWrapper: NSObject {
     var success: Bool = false
     var result: NSDictionary = [:]
-//    var message: String = ""
-//    var code : Int = 200
-//    var error: NSError?
-//    var state: KMAIRewritingState = .rewrite
+ 
     var content: String = ""
-
-//    init(success: Bool, result: NSDictionary, message: String, code: Int, error: NSError? = nil, state: KMAIRewritingState) {
-//        self.success = success
-//        self.result = result
-//        self.message = message
-//        self.code = code
-//        self.error = error
-//        self.state = state
-//    }
+ 
     init(success: Bool, content: String) {
         self.success = success
         self.content = content
@@ -76,7 +65,7 @@ class ResultWrapper: NSObject {
                 if success {
                     let fileData = wrapper.result
                     complete(wrapper)
-//                    aiTranslationFileTranslateHandle(fileKey: fileKey, from: languageAbbreviation(from), to: languageAbbreviation(to), complete: complete)
+ 
                 } else {
                     complete(wrapper)
                 }
@@ -236,12 +225,8 @@ class ResultWrapper: NSObject {
      @param complete 上传完成回调
      */
     private func aiTranslationFileUpload(file: String, complete: @escaping KMRequestServerComplete) {
-        let token: String = KMMemberInfo.shared.access_token
-        if token == "" {
-            return
-        }
         let infoDictionary = Bundle .main.infoDictionary!
-        let urlString = AIInfoConfig().aiActionURL + "/member-system-website/v1/translate/fileUpload"
+        let urlString = AIInfoConfig().aiActionURL + "/api/AI/uploadTranslate"
         let fileData = FileManager.default.contents(atPath: file)
         let params: [String: Any] = ["file": fileData,
                                      "uuid": uuid(),
@@ -253,7 +238,6 @@ class ResultWrapper: NSObject {
             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")
-            requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
         } completion: { task, responseObject, error in
             if responseObject != nil {
                 let data: NSDictionary = responseObject!["data"] as? NSDictionary ?? [:]
@@ -267,14 +251,7 @@ class ResultWrapper: NSObject {
                 
                 let message: String = responseObject!["message"] as? String ?? "unknown error"
                 let error = NSError(domain: message, code: Int(code)!)
-//                let result = ResultWrapper(success: true, result: data, message: message, code: Int(code)!, error: error, state: .uploadTranslate)
-//                if result.code == 200 {
-//                    result.success = true
-//                    complete(result)
-//                } else {
-//                    result.success = false
-//                    complete(result)
-//                }
+ 
                 if Int(code)! == 200 {
                     let wrapper = ResultWrapper(success: true, resultData: data)
                     wrapper.content = data["fileKey"] as! String
@@ -289,10 +266,7 @@ class ResultWrapper: NSObject {
                     complete(wrapper)
                 }
             } else {
-//                let error = NSError(domain: "unknown error", code: 404)
-//                let result = ResultWrapper(success: false, result: [:], message: "unknown error", code: 404, error: error, state: .uploadTranslate)
-//                complete(result)
-                complete(ResultWrapper(success: false, content: "unknown error"))
+                 complete(ResultWrapper(success: false, content: "unknown error"))
             }
         }
     }
@@ -304,12 +278,9 @@ class ResultWrapper: NSObject {
      @param to 结束语言
      */
     func aiTranslationFileTranslateHandle(fileKey: String, from: String, to: String, complete: @escaping KMRequestServerComplete) {
-        let token: String = KMMemberInfo.shared.access_token
-        if token == "" {
-            return
-        }
+        
         let infoDictionary = Bundle .main.infoDictionary!
-        let urlString = AIInfoConfig().aiActionURL + "/member-system-website/v1/translate/fileTranslateHandle"
+        let urlString = AIInfoConfig().aiActionURL + "/api/AI/fileTranslate"
 
         let paraDict = ["fileKey": fileKey,
                         "from": languageAbbreviation(from),
@@ -323,7 +294,6 @@ class ResultWrapper: NSObject {
         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("Bearer " + token, forHTTPHeaderField: "Authorization")
 
         request.httpMethod = "POST"
         request.httpBody = postData
@@ -339,14 +309,7 @@ class ResultWrapper: NSObject {
                 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)!)
-//                let result = ResultWrapper(success: true, result: data1, message: message, code: Int(code)!, error: error, state: .fileTranslate)
-//                if result.code == 200 {
-//                    result.success = true
-//                    complete(result)
-//                } else {
-//                    result.success = false
-//                    complete(result)
-//                }
+ 
                 if Int(code)! == 200 {
                     let fileUrl = data1["fileUrl"]
                     let downFileUrl = data1["downFileUrl"]
@@ -357,15 +320,11 @@ class ResultWrapper: NSObject {
                     let toStr = data1["to"]
                     
                     self.downFileName = downFileName as! String
-//                    self.downloadFile(filePath: ossDownUrl as! String, downFileName: downFileName as! String)
-                    complete(ResultWrapper(success: true, content: ossDownUrl as! String))
+                     complete(ResultWrapper(success: true, content: ossDownUrl as! String))
                 } else {
                     complete(ResultWrapper(success: false, content: message))
                 }
             } else {
-//                let error = NSError(domain: "unknown error", code: 404)
-//                let result = ResultWrapper(success: false, result: [:], message: "unknown error", code: 404, error: error, state: .fileTranslate)
-//                complete(result)
                 complete(ResultWrapper(success: false, content: "unknown error"))
             }
         }
@@ -379,12 +338,9 @@ class ResultWrapper: NSObject {
      @param to 结束语言
      */
     private func aiTranslationTextTrans(q: String, from: String, to: String, complete: @escaping KMRequestServerComplete) {
-        let token: String = KMMemberInfo.shared.access_token
-        if token == "" {
-            return
-        }
+        
         let infoDictionary = Bundle .main.infoDictionary!
-        let urlString = AIInfoConfig().aiActionURL + "/member-system-website/v1/translate/textTrans"
+        let urlString = AIInfoConfig().aiActionURL + "/api/AI/textTranslate"
         
         var escapedString = q
         escapedString = String(data: escapedString.data(using: .utf8)!, encoding: .utf8)!
@@ -399,7 +355,6 @@ class ResultWrapper: NSObject {
         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("Bearer " + token, forHTTPHeaderField: "Authorization")
 
         request.httpMethod = "POST"
         request.httpBody = postData
@@ -434,13 +389,10 @@ class ResultWrapper: NSObject {
      @param state  类型
      */
     private func aiRewriting(content: String, state: KMAIRewritingState, complete: @escaping KMRequestServerComplete) {
-        let token: String = KMMemberInfo.shared.access_token
-        if token == "" {
-            return
-        }
-        var urlString = AIInfoConfig().aiActionURL + "/member-system-website/api/rewrite"
+        
+        var urlString = AIInfoConfig().aiActionURL + "/api/AI/rewrite"
         if state == .correctTypos {
-            urlString = AIInfoConfig().aiActionURL + "/member-system-website/api/correct-typos"
+            urlString = AIInfoConfig().aiActionURL + "/api/AI/correctTypos"
         }
         let params: [String: Any] = ["content": content,
                                      "uuid": uuid(),
@@ -451,19 +403,19 @@ class ResultWrapper: NSObject {
             
         } 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 != nil {
                 let data: NSDictionary = responseObject!["data"] as? NSDictionary ?? [:]
                 let code: String = responseObject!["code"] as? String ?? "06005"
                 let message: String = responseObject!["message"] as? String ?? "unknown error"
                 let error = NSError(domain: message, code: Int(code)!)
+ 
                 if Int(code)! == 200 {
                     complete(ResultWrapper(success: true, content: data["content"] as! String))
                 } else {
                     complete(ResultWrapper(success: false, content: message))
                 }
-            } else {
+            } else { 
                 complete(ResultWrapper(success: false, content: "unknown error"))
             }
         }
@@ -474,12 +426,9 @@ class ResultWrapper: NSObject {
      @param file  文件路径
      */
     private func extractSummaryFile(file: String, complete: @escaping KMRequestServerComplete) {
-        let token: String = KMMemberInfo.shared.access_token
-        if token == "" {
-            return
-        }
+        
         let infoDictionary = Bundle .main.infoDictionary!
-        let urlString = AIInfoConfig().aiActionURL + "/member-system-website/api/extract-file-summary"
+        let urlString = AIInfoConfig().aiActionURL + "/api/AI/extractSummaryFile"
         let fileData = FileManager.default.contents(atPath: file)
         let params: [String: Any] = ["file": fileData,
                                      "uuid": uuid(),
@@ -490,13 +439,13 @@ class ResultWrapper: NSObject {
             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")
-            requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
         } completion: { task, responseObject, error in
             if responseObject != nil {
                 let data: NSDictionary = responseObject!["data"] as? NSDictionary ?? [:]
                 let code: Int = responseObject!["code"] as? Int ?? 06005
                 let message: String = responseObject!["message"] as? String ?? "unknown error"
                 let error = NSError(domain: message, code: code)
+ 
                 if code == 200 {
                     complete(ResultWrapper(success: true, content: data["summary"] as! String))
                 } else {
@@ -504,7 +453,7 @@ class ResultWrapper: NSObject {
                 }
             } else {
                 let error = NSError(domain: "unknown error", code: 404)
-                complete(ResultWrapper(success: false, content: "unknown error"))
+                 complete(ResultWrapper(success: false, content: "unknown error"))
             }
         }
     }

+ 5 - 3
PDF Office/PDF Master/Class/Purchase/DMG/Verification/KMVerificationMessageViewController.m

@@ -200,9 +200,11 @@ NSPopoverDelegate>
         buttonWidth = btnRect.size.width + 10;
     }
     if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
-        self.aiContendView.hidden = NO;
-        totalWidth+=aiWidth;
-        totalWidth+=4;
+        if(IAPProductsManager.defaultManager.aiAllAccessPack12month_pro.isTrialPeriod == false) {
+            self.aiContendView.hidden = NO;
+            totalWidth+=aiWidth;
+            totalWidth+=4;
+        }
     }
     if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1 ||
         [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||

+ 5 - 4
PDF Office/PDF Master/Class/Purchase/DMG/Verification/VerificationManager/AIInfoManager.m

@@ -281,12 +281,13 @@ static AIInfoManager *__Manager = nil;
                 self.aiInfo = aiInfo;
                 self.aiInfoValid = YES;
                 
-                NSString *notificationName = (NSString *)kDeviceAIStatusChangeNotification;
-                [[NSNotificationCenter defaultCenter] postNotificationName:notificationName
-                                                                    object:self
-                                                                       userInfo:info];
             }
             
+            NSString *notificationName = (NSString *)kDeviceAIStatusChangeNotification;
+            [[NSNotificationCenter defaultCenter] postNotificationName:notificationName
+                                                                object:self
+                                                                   userInfo:info];
+            
 #if VERSION_DMG
 #else
             if (isReceiptNeverUsed && [IAPProductsManager defaultManager].temptransactioReceipt) {

+ 21 - 20
PDF Office/PDF Master/Class/Purchase/DMG/Verification/VerificationManager/KMAdsInfo.swift

@@ -86,30 +86,31 @@ enum KMDFPJumpType: Int {
     
     var adsImage: NSImage {
         get {
-            let imageDict: [String: Any] = self.infoDict["dfpImage"] as! [String : Any]
-            let imageURLString = imageDict[self.languageKey] as! NSString
-            
-            var imageName = self.versionKey
-            imageName.append(String(format: "_%@.%@", self.languageKey, imageURLString.lastPathComponent))
- 
-            let kImageCacheFilePath: String = NSTemporaryDirectory() + "Advertisement/ImageCache"
-            let imgSavePath = kImageCacheFilePath + "/" + imageName
-            if FileManager.default.fileExists(atPath: imgSavePath) {
-                return NSImage(contentsOfFile: imgSavePath)!
-            }
-             
-            DispatchQueue.global().async {
-                if let url = URL(string: imageURLString as String),
-                   let imageData = try? Data(contentsOf: url) {
-                    if imageData.isEmpty == false {
-                        DispatchQueue.main.async {
-                            try?imageData.write(to: URL(fileURLWithPath: imgSavePath))
-                            NotificationCenter.default.post(name: Notification.Name(rawValue: "KMRecommondInfoUpdateNoti"), object: ["unique":self.versionKey])
+            if self.infoDict.value(forKey: "dfpImage") != nil {
+                let imageDict: [String: Any] = self.infoDict["dfpImage"] as! [String : Any]
+                let imageURLString = imageDict[self.languageKey] as! NSString
+                
+                var imageName = self.versionKey
+                imageName.append(String(format: "_%@.%@", self.languageKey, imageURLString.lastPathComponent))
+                
+                let kImageCacheFilePath: String = NSTemporaryDirectory() + "Advertisement/ImageCache"
+                let imgSavePath = kImageCacheFilePath + "/" + imageName
+                if FileManager.default.fileExists(atPath: imgSavePath) {
+                    return NSImage(contentsOfFile: imgSavePath)!
+                }
+                
+                DispatchQueue.global().async {
+                    if let url = URL(string: imageURLString as String),
+                       let imageData = try? Data(contentsOf: url) {
+                        if imageData.isEmpty == false {
+                            DispatchQueue.main.async {
+                                try?imageData.write(to: URL(fileURLWithPath: imgSavePath))
+                                NotificationCenter.default.post(name: Notification.Name(rawValue: "KMRecommondInfoUpdateNoti"), object: ["unique":self.versionKey])
+                            }
                         }
                     }
                 }
             }
-             
             return NSImage(named: "ComPDFKit_EN")!
         }
     }