Initial commit
This commit is contained in:
@ -6,3 +6,84 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
/*
|
||||
class GlobalConfig : ObservableObject{
|
||||
@Published var backgroundColor : UInt = 0xFFE4E1
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
class GlobalEnvironment: ObservableObject {
|
||||
@Published var backgroundColor : UInt = 0xFFE4E1
|
||||
|
||||
init(){
|
||||
SetEnv(isSandBox: false, isTestEnv: false)
|
||||
}
|
||||
|
||||
@Published var deviceID: String = ""
|
||||
@Published var userID: String = ""
|
||||
@Published var userName: String = ""
|
||||
@Published var GID: Int = 0
|
||||
@Published var isVip:Bool = false
|
||||
|
||||
// APP 信息
|
||||
let APPID = "6504465465"
|
||||
|
||||
// toast 展示事件
|
||||
let toastPresentMsNormal = 1.5
|
||||
let toastPresentMsLong = 3.0
|
||||
let toastPresentMsShot = 0.5
|
||||
|
||||
// 定义各功能的输入长度限制
|
||||
let MaxLenGrammarCheckFree = 200
|
||||
let MaxLenGrammarCheckVIP = 2000
|
||||
let MaxLenWords = 50
|
||||
let MaxLenTranslate = 200
|
||||
|
||||
// 错误码及错误提示定义
|
||||
let RetCodeFreeLimited = 101000
|
||||
let RetCodeDirtyInput = 101001
|
||||
let GrammarCheckOK = 102000
|
||||
let GrammarOKToast = "Congratulations! There are no errors in your input."
|
||||
let FreeLimitedToast = "Your free usage has been used up. Please upgrade to PREMIUM for unlimited usage."
|
||||
let NetWorkErrToast = "Network Error. Please try again later."
|
||||
let OtherServerErrToast = "Sorry, something went wrong on the server. Please try again later."
|
||||
let DirtyInputErrToast = "The text you entered contains content that does not comply with regulations. Please re-enter."
|
||||
|
||||
var jwtSecret: String = "mCTf-JhNRnhaaGJy_x"
|
||||
|
||||
var userTermsURL: String = "https://grammar.easyprompt8.com/about/"
|
||||
|
||||
// 请求地址,区分环境。
|
||||
// var baseHost: String = "http://192.168.2.2:1080"
|
||||
var baseHost: String = "https://api.easyprompt8.com"
|
||||
|
||||
// 业务请求URL
|
||||
var feedbackURL: String { "\(baseHost)/grammar/feedback" }
|
||||
var translateURL: String { "\(baseHost)/grammar/translate" }
|
||||
var dictURL: String { "\(baseHost)/grammar/words" }
|
||||
var grammarURL: String { "\(baseHost)/grammar/grammar" }
|
||||
|
||||
// 用户请求URL
|
||||
var userURL: String { "\(baseHost)/user/get" }
|
||||
|
||||
// 验证appstore购买
|
||||
var iapVerifyURL : String { "\(baseHost)/iap/verify" }
|
||||
|
||||
// 设置运行环境
|
||||
func SetEnv(isSandBox: Bool, isTestEnv: Bool){
|
||||
if(isTestEnv){
|
||||
self.baseHost = "https://dev.easyprompt8.com"
|
||||
}else {
|
||||
self.baseHost = "https://api.easyprompt8.com"
|
||||
}
|
||||
logger.info("baseHost: \(self.baseHost)")
|
||||
// 以后定义SandBox的功能,主要是商品列表的区分。
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 全局实例
|
||||
let globalEnvironment = GlobalEnvironment()
|
||||
|
||||
@ -7,16 +7,127 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
struct GrammarRes {
|
||||
var tPlain : String
|
||||
var tType : String
|
||||
var tReason : String
|
||||
var tCorrection : [String]
|
||||
// 确保GrammarRes遵循Codable协议,以支持JSON解析
|
||||
struct GrammarRes: Codable {
|
||||
var plain: String
|
||||
var type: String
|
||||
var reason: String
|
||||
var correction: [String]
|
||||
}
|
||||
|
||||
struct GrammarData {
|
||||
var tInputText : String
|
||||
var tCorrectText : String
|
||||
var tResult : [GrammarRes]
|
||||
enum GrammarResType : String {
|
||||
case ok = "ok"
|
||||
case grammar = "grammar"
|
||||
case spell = "spell"
|
||||
}
|
||||
|
||||
|
||||
// 因为tResult是动态的,所以我们定义GrammarData为类
|
||||
class GrammarData {
|
||||
var inputText: String
|
||||
var correctText: String
|
||||
var results: [GrammarRes]
|
||||
|
||||
init(inputText: String, correctText: String, tResult: [GrammarRes] = []) {
|
||||
self.inputText = inputText
|
||||
self.correctText = correctText
|
||||
self.results = tResult
|
||||
}
|
||||
|
||||
// 方法:解析长字符串为tResult
|
||||
func parseResult(from jsonString: String) -> Bool {
|
||||
// 移除字符串中可能出现的多余逗号和空格
|
||||
let cleanedString = jsonString.trimmingCharacters(in: .whitespacesAndNewlines).replacingOccurrences(of: ", ]", with: "]")
|
||||
|
||||
guard let jsonData = cleanedString.data(using: .utf8) else {
|
||||
print("Error: Cannot create jsonData")
|
||||
return false
|
||||
}
|
||||
|
||||
do {
|
||||
// 解析JSON数据
|
||||
self.results = try JSONDecoder().decode([GrammarRes].self, from: jsonData)
|
||||
return true
|
||||
} catch {
|
||||
print("Error: \(error)")
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension GrammarData {
|
||||
// 静态方法返回包含Demo数据的GrammarData实例
|
||||
static func demoInstance() -> GrammarData {
|
||||
//let demoInputText = "This is a demo text with more complex grammar checking algorithm of the pro version. This app have been designed to help you to write correctly and appear more professional. I work really hard to make this app as god as possible. If you are happy with the results, please consider supporting the app by subscribing to the PRO plan. The text writen here is to show you how much the app is capable of with the pro version. is this something you would like to use? "
|
||||
|
||||
let demoInputText = "Paris are hosting the Olypmic Games in 2024. Athletes from arround the world comes to compet in many sports, wich makes it an excting event to watch."
|
||||
|
||||
let demoCorrectText = demoInputText
|
||||
|
||||
// 假设的Demo错误数据
|
||||
let demoErrors = [
|
||||
GrammarRes(plain: "This is a demo text with more complex grammar checking algorithm of the pro version.",
|
||||
type: "ok",
|
||||
reason: "",
|
||||
correction: []),
|
||||
|
||||
GrammarRes(
|
||||
plain: "This app have",
|
||||
type: "grammar",
|
||||
reason: "subject-verb agreement",
|
||||
correction: ["This app has"]
|
||||
),
|
||||
GrammarRes(
|
||||
plain: "been designed to help you to write correctly and appear more professional.",
|
||||
type: "ok",
|
||||
reason: "",
|
||||
correction: []
|
||||
),
|
||||
GrammarRes(
|
||||
plain: "I work really hard",
|
||||
type: "ok",
|
||||
reason: "",
|
||||
correction: []
|
||||
),
|
||||
GrammarRes(
|
||||
plain: "to make this app as god",
|
||||
type: "spell",
|
||||
reason: "typo",
|
||||
correction: ["as good"]
|
||||
),
|
||||
GrammarRes(
|
||||
plain: "as possible.",
|
||||
type: "ok",
|
||||
reason: "",
|
||||
correction: []
|
||||
),
|
||||
GrammarRes(
|
||||
plain: "If you are happy with the results, please consider supporting the app by subscribing to the PRO plan.",
|
||||
type: "ok",
|
||||
reason: "",
|
||||
correction: []
|
||||
),
|
||||
GrammarRes(
|
||||
plain: "The text writen",
|
||||
type: "spell",
|
||||
reason: "misspelling",
|
||||
correction: ["written"]
|
||||
),
|
||||
GrammarRes(
|
||||
plain: "here is to show you how much the app is capable of with the pro version.",
|
||||
type: "ok",
|
||||
reason: "",
|
||||
correction: []
|
||||
),
|
||||
GrammarRes(
|
||||
plain: "is this something you would like to use?",
|
||||
type: "grammar",
|
||||
reason: "capitalization",
|
||||
correction: ["Is this something you would like to use?"]
|
||||
)
|
||||
]
|
||||
|
||||
return GrammarData(inputText: demoInputText, correctText: demoCorrectText, tResult: demoErrors)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user