|
@@ -116,42 +116,44 @@ class KMAITranslationVC: NSViewController {
|
|
|
openPanel.beginSheetModal(for: self.view.window!) { result in
|
|
|
if result == .OK {
|
|
|
for url in openPanel.urls {
|
|
|
- if !url.path.isPDFValid() {
|
|
|
- let alert = NSAlert()
|
|
|
- alert.alertStyle = .critical
|
|
|
- alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
|
|
|
- alert.runModal()
|
|
|
+ if (url.pathExtension == "pdf") || url.pathExtension == "PDF" {
|
|
|
+ if !url.path.isPDFValid() {
|
|
|
+ let alert = NSAlert()
|
|
|
+ alert.alertStyle = .critical
|
|
|
+ alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
|
|
|
+ alert.runModal()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if self.isFileGreaterThan10MB(atPath: url.path) {
|
|
|
+ self.errorView.isHidden = false
|
|
|
+ self.errorLabel.stringValue = NSLocalizedString("The uploaded file cannot exceed 10MB", comment: "")
|
|
|
} else {
|
|
|
- if self.isFileGreaterThan10MB(atPath: url.path) {
|
|
|
- self.errorView.isHidden = false
|
|
|
- self.errorLabel.stringValue = NSLocalizedString("The uploaded file cannot exceed 10MB", comment: "")
|
|
|
- } else {
|
|
|
- DispatchQueue.main.async {
|
|
|
- self.showProgressWindow()
|
|
|
- }
|
|
|
-
|
|
|
- let infoDictionary = Bundle .main.infoDictionary!
|
|
|
- let majorVersion = infoDictionary["CFBundleShortVersionString"]
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ self.showProgressWindow()
|
|
|
+ }
|
|
|
+
|
|
|
+ let infoDictionary = Bundle .main.infoDictionary!
|
|
|
+ let majorVersion = infoDictionary["CFBundleShortVersionString"]
|
|
|
|
|
|
- KMRequestServerManager.manager.aiTranslationFileUpload(file: url.path, version: "1.0.1") { [unowned self] success, result in
|
|
|
- // self.hiddenProgressWindow()
|
|
|
- if success {
|
|
|
- let result: NSDictionary = result!.result
|
|
|
+ KMRequestServerManager.manager.aiTranslationFileUpload(file: url.path, version: "1.0.1") { [unowned self] success, result in
|
|
|
+// self.hiddenProgressWindow()
|
|
|
+ if success {
|
|
|
+ let result: NSDictionary = result!.result
|
|
|
|
|
|
- let fileKey = result["fileKey"]
|
|
|
- let fileName = result["fileName"]
|
|
|
- let pageCount = result["pageCount"]
|
|
|
- if fileKey != nil {
|
|
|
- self.fileTranslateHandle(fileKey as! String)
|
|
|
- }
|
|
|
- } else {
|
|
|
- let result: String = result!.message
|
|
|
+ let fileKey = result["fileKey"]
|
|
|
+ let fileName = result["fileName"]
|
|
|
+ let pageCount = result["pageCount"]
|
|
|
+ if fileKey != nil {
|
|
|
+ self.fileTranslateHandle(fileKey as! String)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ let result: String = result!.message
|
|
|
|
|
|
- DispatchQueue.main.async {
|
|
|
- self.hiddenProgressWindow()
|
|
|
- self.errorView.isHidden = false
|
|
|
- self.errorLabel.stringValue = result
|
|
|
- }
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ self.hiddenProgressWindow()
|
|
|
+ self.errorView.isHidden = false
|
|
|
+ self.errorLabel.stringValue = result
|
|
|
}
|
|
|
}
|
|
|
}
|