|
@@ -106,88 +106,25 @@ class ASGenerateTTPOperation:ASGenerateBaseOperation , @unchecked Sendable{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- 1.用户上传图片
|
|
|
- 2.调用生成接口
|
|
|
- 3.后台返回查询 id,根据 id 不断查询进度和结果.(此时才允许进度后台)
|
|
|
-
|
|
|
- 利用3后台返回的ASActionRequestModel中存着关键的请求接口数据,请求数据
|
|
|
-
|
|
|
- */
|
|
|
-
|
|
|
private var uploadRequest:Request?
|
|
|
private var creatRequest:Request?
|
|
|
|
|
|
func createActionInfoModel(generateStyleModel:ASGenerateStyleModel) ->ASActionInfoModel{
|
|
|
-
|
|
|
-// guard let upLoadImageUrl = generateStyleModel.upLoadImageUrl else { return nil }
|
|
|
-
|
|
|
let infoModel = ASActionInfoModel()
|
|
|
infoModel.id = Date.timestampInt
|
|
|
infoModel.request = ASActionRequestModel()
|
|
|
|
|
|
infoModel.request.prompt = generateStyleModel.prompt
|
|
|
infoModel.request.inputText = generateStyleModel.inputText
|
|
|
-
|
|
|
-// infoModel.request.style = generateStyleModel.style
|
|
|
-// infoModel.request.advance = generateStyleModel.advance
|
|
|
-// infoModel.request.imageUrl = upLoadImageUrl
|
|
|
-// infoModel.request.imageUrlTimestamp = Date.timestampInt
|
|
|
-
|
|
|
-
|
|
|
return infoModel
|
|
|
}
|
|
|
|
|
|
-// func uploadImage(generateStyleModel:ASGenerateStyleModel,complete:@escaping (ASActionInfoModel?)->Void) {
|
|
|
-//
|
|
|
-// guard let upLoadImage = generateStyleModel.upLoadImage else { return }
|
|
|
-// if let imageUrl = generateStyleModel.upLoadImageUrl,imageUrl.contains("http") {
|
|
|
-// complete(createActionInfoModel(generateStyleModel: generateStyleModel))
|
|
|
-// return
|
|
|
-// }
|
|
|
-//
|
|
|
-// stopNetwork = false
|
|
|
-// stateDatauPblished = (.start,nil)
|
|
|
-//
|
|
|
-// stateDatauPblished = (.progressString(uploadingPhoto(progress: 0.0)),currentActionInfoModel)
|
|
|
-// uploadRequest =AINetworkManager.uploadImage(upLoadImage: upLoadImage, maxKb: imageMaxKb) { [weak self] progress in
|
|
|
-// guard let self = self else { return }
|
|
|
-// if generatingProgress == 0 {
|
|
|
-// stateDatauPblished = (.progressString(uploadingPhoto(progress: progress)),currentActionInfoModel)
|
|
|
-// }
|
|
|
-// } completion: { [weak self] data, error in
|
|
|
-// guard let self = self else { return }
|
|
|
-// if stopNetwork == true { return }
|
|
|
-// if let error = error {
|
|
|
-// generateStyleModel.upLoadImageUrl = nil
|
|
|
-// self.stateDatauPblished = (ASProgressState.getFailed(error.tsDesc,error.tsCode),nil)
|
|
|
-// complete(nil)
|
|
|
-// }else{
|
|
|
-// if let string = data as? String {
|
|
|
-// generateStyleModel.upLoadImageUrl = string
|
|
|
-// if let url = URL(string: string){//上传成功后,就将图片缓存到本地
|
|
|
-// ImageCache.default.store(upLoadImage, forKey: url.cacheKey)
|
|
|
-// }
|
|
|
-//
|
|
|
-// complete(createActionInfoModel(generateStyleModel: generateStyleModel))
|
|
|
-// }else{
|
|
|
-// complete(nil)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
|
|
|
func creatImage(oldModel:ASActionInfoModel,complete:@escaping (Bool)->Void) {
|
|
|
|
|
|
initializeActionInfoModel(oldModel: oldModel)
|
|
|
-// if oldModel.upImageURLExpired { return }
|
|
|
-
|
|
|
- generatingProgress = 0
|
|
|
stopNetwork = false
|
|
|
|
|
|
-
|
|
|
-
|
|
|
currentActionInfoModel.status = "running"
|
|
|
currentActionInfoModel.actionStatus = .running
|
|
|
currentActionInfoModel.percent = 0
|
|
@@ -204,12 +141,11 @@ class ASGenerateTTPOperation:ASGenerateBaseOperation , @unchecked Sendable{
|
|
|
prompt = inputText
|
|
|
}
|
|
|
}
|
|
|
- let width = 800.0
|
|
|
- let height = 1440.0
|
|
|
+
|
|
|
creatRequest = AINetworkManager.post(endpoint:.textToImage,parameters:
|
|
|
["prompt":prompt,
|
|
|
- "width":width,
|
|
|
- "height":height,
|
|
|
+ "width":800.0,
|
|
|
+ "height":1440.0,
|
|
|
"device":AIGetUserInfoJsonString,
|
|
|
]) { [weak self] data,error in
|
|
|
guard let self = self else { return }
|
|
@@ -235,28 +171,13 @@ class ASGenerateTTPOperation:ASGenerateBaseOperation , @unchecked Sendable{
|
|
|
}
|
|
|
override func generating(progress: Float) -> String {
|
|
|
let progress = Float(progress)*(kPercentScale) // 预留 10% 进度给图片下载
|
|
|
- //Generating 0%-100%
|
|
|
var progressInt = Int(progress*100)
|
|
|
-
|
|
|
- if progressInt > 99 {
|
|
|
- progressInt = 99
|
|
|
- }
|
|
|
-
|
|
|
- generatingProgress = progressInt
|
|
|
return "Generating".localized + " \(progressInt)%"
|
|
|
}
|
|
|
|
|
|
- var imageMaxKb:Int{
|
|
|
- return 10*1024
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
func uploadingPhoto(progress:Float) -> String {
|
|
|
- //Uploading Photo 0%-100%
|
|
|
- var progressInt = Int(progress*100)
|
|
|
- if progressInt > 99 {
|
|
|
- progressInt = 99
|
|
|
- }
|
|
|
- return "Uploading Photo".localized + " \(progressInt)%"
|
|
|
+ return "Uploading Photo".localized + " \(Int(progress*100))%"
|
|
|
}
|
|
|
|
|
|
|