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