123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- //
- // TSUserDefaultData.swift
- // AIRingtone
- //
- // Created by 100Years on 2025/3/5.
- //
- import ObjectMapper
- //海报历史记录
- class TSPosterHistory{
- @UserDefault(key: "kPosterTextPicHistoryListString", defaultValue: "")
- static private var historyString: String
- static var listModelArray: [TSActionInfoModel] = {
-
- if UserDefaults.standard.string(forKey: "insertPosterExampleData") == nil {
- insertExampleData()
- UserDefaults.standard.set("1", forKey: "insertPosterExampleData")
- UserDefaults.standard.synchronize()
- }
-
- if let listModelArray = Mapper<TSActionInfoModel>().mapArray(JSONString: historyString){
- return listModelArray
- }
- return []
- }()
-
- static func saveModel(model:TSActionInfoModel){
- listModelArray.insert(model, at: 0)
- saveHistoryString()
- }
-
- static func removeModel(model:TSActionInfoModel){
- listModelArray.removeAll { $0 === model }
- saveHistoryString()
- }
-
- static func removeIndex(index:Int){
- listModelArray.remove(at: index)
- saveHistoryString()
- }
-
- static func saveHistoryString(){
- if let jsonString = listModelArray.toJSONString() {
- historyString = jsonString
- }
- }
-
- private static func insertExampleData(){
- let array = [
- createExampleModel(imageName: "poster_example_0"),
- createExampleModel(imageName: "poster_example_1"),
- createExampleModel(imageName: "poster_example_2")
- ]
- if let jsonString = array.toJSONString() {
- historyString = jsonString
- }
- }
-
- private static func createExampleModel(imageName:String)->TSActionInfoModel{
- let model = TSActionInfoModel()
- model.modelType = .example
- model.request.prompt = "Example"
- model.request.promptSort = "Example"
- model.request.width = kTextPicW
- model.request.height = kTextPicH
- model.response.resultUrl = imageName
- return model
- }
- }
- //头像历史记录
- class TSPhotoHistory{
- @UserDefault(key: "kPhotoTextPicHistoryListString", defaultValue: "")
- static private var historyString: String
- static var listModelArray: [TSActionInfoModel] = {
- if UserDefaults.standard.string(forKey: "insertPhotoExampleData") == nil {
- insertExampleData()
- UserDefaults.standard.set("1", forKey: "insertPhotoExampleData")
- UserDefaults.standard.synchronize()
- }
- if let listModelArray = Mapper<TSActionInfoModel>().mapArray(JSONString: historyString){
- return listModelArray
- }
- return []
- }()
-
- static func saveModel(model:TSActionInfoModel){
- listModelArray.insert(model, at: 0)
- saveHistoryString()
- }
-
- static func removeModel(model:TSActionInfoModel){
- listModelArray.removeAll { $0 === model }
- saveHistoryString()
- }
-
- static func removeIndex(index:Int){
- listModelArray.remove(at: index)
- saveHistoryString()
- }
-
- static func saveHistoryString(){
- if let jsonString = listModelArray.toJSONString() {
- historyString = jsonString
- }
- }
-
- private static func insertExampleData(){
- let array = [
- createExampleModel(imageName: "photo_example_0"),
- createExampleModel(imageName: "photo_example_1"),
- createExampleModel(imageName: "photo_example_2")
- ]
- if let jsonString = array.toJSONString() {
- historyString = jsonString
- }
- }
-
- private static func createExampleModel(imageName:String)->TSActionInfoModel{
- let model = TSActionInfoModel()
- model.modelType = .example
- model.request.prompt = "Example"
- model.request.promptSort = "Example"
- model.request.width = kTextPicW
- model.request.height = kTextPicW
- model.response.resultUrl = imageName
- return model
- }
- }
- //AI铃声历史记录
- class TSAIRintoneHistory{
- @UserDefault(key: "kRintoneTextMusicHistoryListString", defaultValue: "")
- static private var historyString: String
- static var listModelArray: [TSActionInfoModel] = {
-
- if UserDefaults.standard.string(forKey: "insertRintoneExampleData") == nil {
- insertExampleData()
- UserDefaults.standard.set("1", forKey: "insertRintoneExampleData")
- UserDefaults.standard.synchronize()
- }
-
- if let listModelArray = Mapper<TSActionInfoModel>().mapArray(JSONString: historyString){
- return listModelArray
- }
- return []
- }()
-
- static func saveModel(model:TSActionInfoModel){
- listModelArray.insert(model, at: 0)
- saveHistoryString()
- }
-
- static func removeModel(model:TSActionInfoModel){
- listModelArray.removeAll { $0 === model }
- saveHistoryString()
- }
-
- static func removeIndex(index:Int){
- listModelArray.remove(at: index)
- saveHistoryString()
- }
-
- static func saveHistoryString(){
- if let jsonString = listModelArray.toJSONString() {
- historyString = jsonString
- }
- }
-
- private static func insertExampleData(){
- let array = [
- createExampleModel(),
- ]
- if let jsonString = array.toJSONString() {
- historyString = jsonString
- }
- }
-
- private static func createExampleModel()->TSActionInfoModel{
- let model = TSActionInfoModel()
- model.modelType = .example
- model.request.duration = 30
- model.request.prompt = "Example"
- model.request.promptSort = "Example"
- model.response.coverUrl = "http://d3a93z8fj970a4.cloudfront.net/53337c41-9610-4b92-a8fc-0871a0895880"
- model.response.title = "Glass"
- model.response.musicUrl = "http://d3a93z8fj970a4.cloudfront.net/328324a2-2576-4f55-8c77-2fa16b88e043"
- return model
- }
- }
|