|
@@ -42,7 +42,7 @@ class TSGeneratePhotoOperation: TSGenerateBaseOperation , @unchecked Sendable{
|
|
|
|
|
|
var gennerateType:TSGennerateType = .photo
|
|
var gennerateType:TSGennerateType = .photo
|
|
|
|
|
|
- func replaceSaveInfoModel(model:TSActionInfoModel){
|
|
|
|
|
|
+ override func replaceSaveInfoModel(model:TSActionInfoModel){
|
|
model.uuid = uuid
|
|
model.uuid = uuid
|
|
TSPhotoHistory.replaceModel(oldID: currentActionInfoModel.id, newModel: model)
|
|
TSPhotoHistory.replaceModel(oldID: currentActionInfoModel.id, newModel: model)
|
|
currentActionInfoModel = model
|
|
currentActionInfoModel = model
|
|
@@ -51,75 +51,76 @@ class TSGeneratePhotoOperation: TSGenerateBaseOperation , @unchecked Sendable{
|
|
currentActionInfoModelChanged?(currentActionInfoModel)
|
|
currentActionInfoModelChanged?(currentActionInfoModel)
|
|
}
|
|
}
|
|
|
|
|
|
- //模拟数据
|
|
|
|
|
|
+// //模拟数据
|
|
|
|
+// func creatPhoto(oldModel:TSActionInfoModel? = nil,prompt:String,promptSort:String) {
|
|
|
|
+// if let model = oldModel {
|
|
|
|
+// currentActionInfoModel = model
|
|
|
|
+// }else {
|
|
|
|
+// currentActionInfoModel.id = Int.timestampInt()
|
|
|
|
+// currentActionInfoModel.request.prompt = prompt
|
|
|
|
+// currentActionInfoModel.request.promptSort = promptSort
|
|
|
|
+// currentActionInfoModel.actionStatus = .pending
|
|
|
|
+// currentActionInfoModel.status = "pending"
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// replaceSaveInfoModel(model: currentActionInfoModel)
|
|
|
|
+// stateDatauPblished = (.start,currentActionInfoModel)
|
|
|
|
+// let time = 5.0
|
|
|
|
+//
|
|
|
|
+// for i in 0..<Int(time){
|
|
|
|
+// kDelayOnMainThread(Double(i)) {
|
|
|
|
+// let progress = Float(i)*10/100.0
|
|
|
|
+// self.currentActionInfoModel.percent = progress
|
|
|
|
+// self.currentActionInfoModel.actionStatus = .running
|
|
|
|
+// self.currentActionInfoModel.status = "running"
|
|
|
|
+// self.replaceSaveInfoModel(model: self.currentActionInfoModel)
|
|
|
|
+// self.stateDatauPblished = (.progressString(self.generating(progress: progress)),nil)
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// kDelayOnMainThread(time+1.0) {
|
|
|
|
+// if kRandomBool(), let infoModel = TSActionInfoModel(JSON: self.actionInfoDict){
|
|
|
|
+// infoModel.id = Int.uuid
|
|
|
|
+// self.replaceSaveInfoModel(model: infoModel)
|
|
|
|
+// self.stateDatauPblished = (.success(nil),self.currentActionInfoModel)
|
|
|
|
+// }else{
|
|
|
|
+// self.currentActionInfoModel.actionStatus = .failed
|
|
|
|
+// self.currentActionInfoModel.status = "failed"
|
|
|
|
+// self.replaceSaveInfoModel(model: self.currentActionInfoModel)
|
|
|
|
+// self.stateDatauPblished = (.failed("error?.localizedDescription"),nil)
|
|
|
|
+// }
|
|
|
|
+//// TSPhotoHistory.dePrintAllModel()
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //width 和 height 必须是 32 的倍数
|
|
func creatPhoto(oldModel:TSActionInfoModel? = nil,prompt:String,promptSort:String) {
|
|
func creatPhoto(oldModel:TSActionInfoModel? = nil,prompt:String,promptSort:String) {
|
|
- if let model = oldModel {
|
|
|
|
- currentActionInfoModel = model
|
|
|
|
- }else {
|
|
|
|
- currentActionInfoModel.id = Int.timestampInt()
|
|
|
|
- currentActionInfoModel.request.prompt = prompt
|
|
|
|
- currentActionInfoModel.request.promptSort = promptSort
|
|
|
|
- currentActionInfoModel.actionStatus = .pending
|
|
|
|
- currentActionInfoModel.status = "pending"
|
|
|
|
- }
|
|
|
|
|
|
+ initializeFirstCurrentActionInfoModel(oldModel: oldModel, prompt: prompt, promptSort: promptSort)
|
|
|
|
|
|
- replaceSaveInfoModel(model: currentActionInfoModel)
|
|
|
|
- stateDatauPblished = (.start,currentActionInfoModel)
|
|
|
|
- let time = 5.0
|
|
|
|
-
|
|
|
|
- for i in 0..<Int(time){
|
|
|
|
- kDelayOnMainThread(Double(i)) {
|
|
|
|
- let progress = Float(i)*10/100.0
|
|
|
|
- self.currentActionInfoModel.percent = progress
|
|
|
|
- self.currentActionInfoModel.actionStatus = .running
|
|
|
|
- self.currentActionInfoModel.status = "running"
|
|
|
|
- self.replaceSaveInfoModel(model: self.currentActionInfoModel)
|
|
|
|
- self.stateDatauPblished = (.progressString(self.generating(progress: progress)),nil)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ generatingProgress = 0
|
|
|
|
|
|
- kDelayOnMainThread(time+1.0) {
|
|
|
|
- if kRandomBool(), let infoModel = TSActionInfoModel(JSON: self.actionInfoDict){
|
|
|
|
- infoModel.id = Int.uuid
|
|
|
|
- self.replaceSaveInfoModel(model: infoModel)
|
|
|
|
- self.stateDatauPblished = (.success(nil),self.currentActionInfoModel)
|
|
|
|
- }else{
|
|
|
|
- self.currentActionInfoModel.actionStatus = .failed
|
|
|
|
- self.currentActionInfoModel.status = "failed"
|
|
|
|
- self.replaceSaveInfoModel(model: self.currentActionInfoModel)
|
|
|
|
- self.stateDatauPblished = (.failed("error?.localizedDescription"),nil)
|
|
|
|
|
|
+ let postDict:[String : Any] = [
|
|
|
|
+ "prompt":prompt,
|
|
|
|
+ "width":textPicW,
|
|
|
|
+ "height":textPicH
|
|
|
|
+ ]
|
|
|
|
+ creatRequest = TSNetworkShared.post(urlType: .textPicCreate,parameters: postDict) { [weak self] data,error in
|
|
|
|
+ guard let self = self else { return }
|
|
|
|
+ if let dataDict = data as? [String:Any] ,
|
|
|
|
+ dataDict.safeInt(forKey: "code") == 200,
|
|
|
|
+ let actionId = dataDict["actionId"] as? Int{
|
|
|
|
+ if stopNetwork == false {
|
|
|
|
+ self.getActionInfo(action_id:actionId)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-// TSPhotoHistory.dePrintAllModel()
|
|
|
|
|
|
+
|
|
|
|
+ handleFailInfoModel(errorString: error?.localizedDescription)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// //width 和 height 必须是 32 的倍数
|
|
|
|
-// func creatImageEmoji(text:String) {
|
|
|
|
-// generatingProgress = 0
|
|
|
|
-// aiText = text
|
|
|
|
-// let postDict:[String : Any] = [
|
|
|
|
-// "prompt":text,
|
|
|
|
-// "width":textPicW,
|
|
|
|
-// "height":textPicH
|
|
|
|
-// ]
|
|
|
|
-// stateDatauPblished = (.start,nil)
|
|
|
|
-// stateDatauPblished = (.progressString(generating(progress: 0.0)),nil)
|
|
|
|
-// creatRequest = TSNetworkShared.post(urlType: .textPicCreate,parameters: postDict) { [weak self] data,error in
|
|
|
|
-// guard let self = self else { return }
|
|
|
|
-// if let dataDict = data as? [String:Any] ,
|
|
|
|
-// dataDict.safeInt(forKey: "code") == 200,
|
|
|
|
-// let actionId = dataDict["actionId"] as? Int{
|
|
|
|
-// if stopNetwork == false {
|
|
|
|
-// self.getActionInfo(action_id:actionId)
|
|
|
|
-// }
|
|
|
|
-// }else{
|
|
|
|
-// self.stateDatauPblished = (.failed(error?.localizedDescription ?? ""),nil)
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
override func getGeneratingProgressText()->String{
|
|
override func getGeneratingProgressText()->String{
|
|
return "Working on your contact Photo \(generatingProgress)% ..."
|
|
return "Working on your contact Photo \(generatingProgress)% ..."
|
|
}
|
|
}
|