|
@@ -82,7 +82,7 @@ class TSGenerateBaseOperation: TSBaseOperation , @unchecked Sendable{
|
|
|
var stopNetwork = false
|
|
|
var generatingProgress = 0
|
|
|
var action_id:Int = 0
|
|
|
-
|
|
|
+ var retryDownloadCount = 0
|
|
|
public var isShowSuccessView:Bool = false //是否展示成功后的 View 提醒
|
|
|
var isSaveProcessToDB:Bool = false //是否保存过程到数据库
|
|
|
{
|
|
@@ -184,7 +184,13 @@ class TSGenerateBaseOperation: TSBaseOperation , @unchecked Sendable{
|
|
|
}
|
|
|
|
|
|
func downResultUrl(infoModel:TSActionInfoModel){
|
|
|
-
|
|
|
+
|
|
|
+ if retryDownloadCount > 3 {
|
|
|
+ debugPrint("生成后下载视频失败,重新尝试超过 3 次,直接失败")
|
|
|
+ handleFailInfoModel(errorString: nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
if generateStyleModel?.generatorStyle == .creatVideo {
|
|
|
let group = DispatchGroup()
|
|
|
//下载视频源
|
|
@@ -203,16 +209,28 @@ class TSGenerateBaseOperation: TSBaseOperation , @unchecked Sendable{
|
|
|
|
|
|
group.notify(queue: .main){[weak self] in
|
|
|
guard let self = self else { return }
|
|
|
- handleSuccess(infoModel: infoModel)
|
|
|
+ if infoModel.response.videoDocument.isEmpty {
|
|
|
+ debugPrint("生成后下载视频失败,重新尝试retryDownloadCount=\(retryDownloadCount)")
|
|
|
+ downResultUrl(infoModel: infoModel)
|
|
|
+ }else{
|
|
|
+ handleSuccess(infoModel: infoModel)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
- downloadImage(urlString: infoModel.response.resultUrl) { [weak self] in
|
|
|
+ downloadImage(urlString: infoModel.response.resultUrl) { [weak self] image in
|
|
|
guard let self = self else { return }
|
|
|
- handleSuccess(infoModel: infoModel)
|
|
|
+ if image == nil {
|
|
|
+ debugPrint("生成后下载视频失败,重新尝试retryDownloadCount=\(retryDownloadCount)")
|
|
|
+ downResultUrl(infoModel: infoModel)
|
|
|
+ }else{
|
|
|
+ handleSuccess(infoModel: infoModel)
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ retryDownloadCount += 1
|
|
|
}
|
|
|
|
|
|
let generatingText:String = "Processing".localized
|
|
@@ -227,7 +245,7 @@ class TSGenerateBaseOperation: TSBaseOperation , @unchecked Sendable{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func downloadImage(urlString:String,completion:@escaping ()->Void){
|
|
|
+ func downloadImage(urlString:String,completion:@escaping (UIImage?)->Void){
|
|
|
TSImageStoreTool.downloadImageWithProgress(urlString: urlString) { [weak self] progress in
|
|
|
guard let self = self else { return }
|
|
|
|
|
@@ -236,7 +254,7 @@ class TSGenerateBaseOperation: TSBaseOperation , @unchecked Sendable{
|
|
|
stateDatauPblished = (.progressString(progressString),currentActionInfoModel)
|
|
|
dePrint("生成后图片下载进度: \(progress)")
|
|
|
} completion: { image in
|
|
|
- completion()
|
|
|
+ completion(image)
|
|
|
}
|
|
|
}
|
|
|
|