|
@@ -518,13 +518,25 @@ class ResultWrapper: NSObject {
|
|
|
}
|
|
|
|
|
|
private func aiMemberTranslationTextTrans(q: String, from: String, to: String, complete: @escaping KMRequestServerComplete) {
|
|
|
- let token: String = KMMemberInfo.shared.access_token
|
|
|
- if token == "" {
|
|
|
- return
|
|
|
+ if(KMMemberInfo.shared.isLogin == true) {
|
|
|
+ KMUserInfoViewController.refreshTokenUserInfo {[weak self] success, resDic in
|
|
|
+ if(success == true) {
|
|
|
+ self?.aiMemberTranslationTextTransReq(q: q, from: from, to: to, complete: complete)
|
|
|
+ } else {
|
|
|
+ let code = resDic?.code ?? 200
|
|
|
+ if(code == 304) {
|
|
|
+ KMLoginWindowsController.shared.showWindow(nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
+ func aiMemberTranslationTextTransReq(q: String, from: String, to: String, complete: @escaping KMRequestServerComplete) {
|
|
|
let urlString = AIInfoConfig().memberAIActionURL + "/member-system-website/v1/translate/textTrans"
|
|
|
-
|
|
|
+ let token: String = KMMemberInfo.shared.access_token
|
|
|
+
|
|
|
var escapedString = q
|
|
|
escapedString = String(data: escapedString.data(using: .utf8)!, encoding: .utf8)!
|
|
|
let paraDict = ["text":escapedString,
|
|
@@ -594,37 +606,54 @@ class ResultWrapper: NSObject {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- let token: String = KMMemberInfo.shared.access_token
|
|
|
- if token == "" {
|
|
|
- return
|
|
|
- }
|
|
|
- var urlString = AIInfoConfig().memberAIActionURL + "/member-system-website/api/rewrite"
|
|
|
- if state == .correctTypos {
|
|
|
- urlString = AIInfoConfig().memberAIActionURL + "/member-system-website/api/correct-typos"
|
|
|
- }
|
|
|
- let params: [String: Any] = ["content": content]
|
|
|
-
|
|
|
- KMAIRequestServer.requestServer.aiMemberRewriting(urlString: urlString, params: params) { formData in
|
|
|
-
|
|
|
- } 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 is KMMemberCenterResult {
|
|
|
- let resultObjct = responseObject as! KMMemberCenterResult
|
|
|
- let code = resultObjct.code
|
|
|
- let message: String = resultObjct.msg ?? ""
|
|
|
- if code == 200 {
|
|
|
- complete(ResultWrapper(success: true, content: message))
|
|
|
+ if(KMMemberInfo.shared.isLogin == true) {
|
|
|
+ KMUserInfoViewController.refreshTokenUserInfo {[weak self] success, resDic in
|
|
|
+ if(success == true) {
|
|
|
+ self?.aiMemberRewriting(content: content, state: state, complete: complete)
|
|
|
} else {
|
|
|
- complete(ResultWrapper(success: false, content: message))
|
|
|
+ let code = resDic?.code ?? 200
|
|
|
+ if(code == 304) {
|
|
|
+ KMLoginWindowsController.shared.showWindow(nil)
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func aiMemberRewriting(content: String, state: KMAIRewritingState, complete: @escaping KMRequestServerComplete) {
|
|
|
+ let token: String = KMMemberInfo.shared.access_token
|
|
|
+ if token == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var urlString = AIInfoConfig().memberAIActionURL + "/member-system-website/api/rewrite"
|
|
|
+ if state == .correctTypos {
|
|
|
+ urlString = AIInfoConfig().memberAIActionURL + "/member-system-website/api/correct-typos"
|
|
|
+ }
|
|
|
+ let params: [String: Any] = ["content": content]
|
|
|
+
|
|
|
+ KMAIRequestServer.requestServer.aiMemberRewriting(urlString: urlString, params: params) { formData in
|
|
|
+
|
|
|
+ } 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 is KMMemberCenterResult {
|
|
|
+ let resultObjct = responseObject as! KMMemberCenterResult
|
|
|
+ let code = resultObjct.code
|
|
|
+ let message: String = resultObjct.msg ?? ""
|
|
|
+ if code == 200 {
|
|
|
+ complete(ResultWrapper(success: true, content: message))
|
|
|
} else {
|
|
|
- complete(ResultWrapper(success: false, content: "unknown error"))
|
|
|
+ complete(ResultWrapper(success: false, content: message))
|
|
|
}
|
|
|
+ } else {
|
|
|
+ complete(ResultWrapper(success: false, content: "unknown error"))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
@abstract 提取摘要
|