瀏覽代碼

AI - 文本翻译时,APP判断页码是否超过30页

wanjun 1 年之前
父節點
當前提交
1920d43472

+ 14 - 0
PDF Office/PDF Master/Class/Home/ViewController/KMAITranslationVC.swift

@@ -116,6 +116,7 @@ class KMAITranslationVC: NSViewController {
                 openPanel.beginSheetModal(for: self.view.window!) { result in
                     if result == .OK {
                         for url in openPanel.urls {
+                            let isExceedsLimit = self.isPDFPageCountExceedsLimit(filePath: url.path)
                             if (url.pathExtension == "pdf") || url.pathExtension == "PDF" {
                                 if !url.path.isPDFValid() {
                                     let alert = NSAlert()
@@ -128,6 +129,9 @@ class KMAITranslationVC: NSViewController {
                             if self.isFileGreaterThan10MB(atPath: url.path) {
                                 self.errorView.isHidden = false
                                 self.errorLabel.stringValue = NSLocalizedString("The uploaded file size cannot exceed 10MB", comment: "")
+                            } else if isExceedsLimit  {
+                                self.errorView.isHidden = false
+                                self.errorLabel.stringValue = NSLocalizedString("Documents cannot exceed 30 pages", comment: "")
                             } else {
                                 DispatchQueue.main.async {
                                     self.showProgressWindow()
@@ -378,6 +382,16 @@ class KMAITranslationVC: NSViewController {
         return false
     }
     
+    func isPDFPageCountExceedsLimit(filePath: String) -> Bool {
+        let url = URL(fileURLWithPath: filePath)
+        guard let document = PDFDocument(url: url) else {
+            return false
+        }
+        
+        let pageCount = document.pageCount
+        return pageCount > 30
+    }
+
     // MARK: Action Methods
     
     func languageAction(_ isFromLanguage: Bool) -> Void {

+ 4 - 0
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController+Action.swift

@@ -603,9 +603,13 @@ extension KMHomeViewController {
             return
         }
         
+        let isExceedsLimit = self.isPDFPageCountExceedsLimit(filePath: path)
         if self.isFileGreaterThan10MB(atPath: path) {
             self.aiTranslationViewController.errorView.isHidden = false
             self.aiTranslationViewController.errorLabel.stringValue = NSLocalizedString("The uploaded file size cannot exceed 10MB", comment: "")
+        } else if isExceedsLimit {
+            self.aiTranslationViewController.errorView.isHidden = false
+            self.aiTranslationViewController.errorLabel.stringValue = NSLocalizedString("Documents cannot exceed 30 pages", comment: "")
         } else {
             let url = URL(fileURLWithPath: path)
             if (url.pathExtension == "pdf") || url.pathExtension == "PDF" {

+ 10 - 0
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController.swift

@@ -639,6 +639,16 @@ import KMAdvertisement
 
         return false
     }
+    
+    func isPDFPageCountExceedsLimit(filePath: String) -> Bool {
+        let url = URL(fileURLWithPath: filePath)
+        guard let document = PDFDocument(url: url) else {
+            return false
+        }
+        
+        let pageCount = document.pageCount
+        return pageCount > 30
+    }
 
     // MARK: Common methods
     

+ 1 - 1
PDF Office/PDF Master/Class/KMLightMember/Manager/KMRequestServerManager.swift

@@ -516,7 +516,7 @@ class KMRequestServerManager: NSObject {
             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 message: String = responseObject!["msg"] as? String ?? "unknown error"
                 let error = NSError(domain: message, code: Int(code)!)
                 let result = Result(result: data,message: message,code: Int(code)!, error: error)
                 if result.code == 200 {

+ 8 - 0
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -1919,12 +1919,20 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
             return
         }
 
+        let isExceedsLimit = self.isPDFPageCountExceedsLimit(filePath: (self.document?.documentURL.path)!)
         if self.isFileGreaterThan10MB(atPath: (self.document?.documentURL.path)!) {
             let alert = NSAlert()
             alert.alertStyle = .critical
             alert.messageText = NSLocalizedString("The uploaded file size cannot exceed 10MB", comment: "")
             alert.runModal()
 
+            return
+        } else if isExceedsLimit  {
+            let alert = NSAlert()
+            alert.alertStyle = .critical
+            alert.messageText = NSLocalizedString("Documents cannot exceed 30 pages", comment: "")
+            alert.runModal()
+
             return
         }
         

+ 10 - 0
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift

@@ -570,6 +570,16 @@ import Cocoa
         return false
     }
     
+    func isPDFPageCountExceedsLimit(filePath: String) -> Bool {
+        let url = URL(fileURLWithPath: filePath)
+        guard let document = PDFDocument(url: url) else {
+            return false
+        }
+        
+        let pageCount = document.pageCount
+        return pageCount > 30
+    }
+    
     // MARK: Redact 【标记密文】
     func exeRedactConfirm(_ type: KMRedactConfirmType, callback: @escaping () -> ()?) {
         let windowController = KMRedactConfirmWindowController(type)

+ 1 - 0
PDF Office/PDF Master/Strings/en.lproj/Localizable.strings

@@ -3850,3 +3850,4 @@
 "The uploaded file size cannot exceed 10MB" = "The uploaded file size cannot exceed 10MB";
 "Scanned PDF files are not supported" = "Scanned PDF files are not supported";
 "Limit document size to 10M, document page number to 30, 10w characters per month." = "Limit document size to 10M, document page number to 30, 10w characters per month.";
+"Documents cannot exceed 30 pages" = "Documents cannot exceed 30 pages";