Initial commit

This commit is contained in:
oscarz
2024-08-12 10:49:20 +08:00
parent 3002510aaf
commit 00fd0adf89
331 changed files with 53210 additions and 130 deletions

View File

@ -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()

View File

@ -7,16 +7,127 @@
import Foundation
struct GrammarRes {
var tPlain : String
var tType : String
var tReason : String
var tCorrection : [String]
// GrammarResCodableJSON
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"
}
// tResultGrammarData
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 {
// DemoGrammarData
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)
}
}