PQUploadViewModel.swift 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // PQUploadViewModel.swift
  3. // PQSpeed
  4. //
  5. // Created by SanW on 2020/8/4.
  6. // Copyright © 2020 BytesFlow. All rights reserved.
  7. //
  8. import BFCommonKit
  9. import BFNetRequestKit
  10. import UIKit
  11. import BFUIKit
  12. import BFAnalyzeKit
  13. public class PQUploadViewModel: NSObject {
  14. /// 发布视频
  15. /// - Parameters:
  16. /// - projectId 项目ID-发布创作的视频时必传,会在进入创作工具页时生成,以app_no_projectdata为前缀
  17. /// - fileExtensions 视频封装格式 -必传
  18. /// - title: 标题
  19. /// - videoPath: 视频地址
  20. /// - coverImgPath: 封面地址
  21. /// - descr: 描述
  22. /// - videoFromScene 视频来源场景 1:普通上传 2:创作工具,3:普通上传转创作工具,4:后台转换加工,5:卡点视频制作
  23. /// - Returns: <#description#>
  24. public class func publishVideo(projectId: String?, fileExtensions: String?, title: String, videoPath: String, coverImgPath: String?, descr: String, videoFromScene: videoFromScene, reCreateData: PQReCreateModel?, eventTrackData: PQVideoMakeEventTrackModel?, topicId: String? = nil,extParams:String? = nil, completeHander: @escaping (_ videoData: PQVideoListModel?, _ jsonDict: [String: Any]?, _ msg: String?) -> Void) {
  25. BFLog(message: "AKAKAAKprojectId is\(String(describing: projectId)) videoFromScene is \(videoFromScene)")
  26. var params: [String: Any] = ["title": title, "fileExtensions": fileExtensions ?? "application/octet-stream", "videoPath": videoPath, "descr": descr, "viewStatus": 1, "produceProjectId": (projectId ?? "") as String, "videoFromScene": videoFromScene.rawValue]
  27. if coverImgPath != nil, (coverImgPath?.count ?? 0) > 0 {
  28. params["coverImgPath"] = coverImgPath
  29. }
  30. if topicId != nil, (topicId?.count ?? 0) > 0 {
  31. params["topicId"] = topicId
  32. }
  33. if extParams != nil && (extParams?.count ?? 0) > 0 {
  34. params["reserve"] = extParams!
  35. }
  36. BFNetRequestAdaptor.postRequestData(url: PQENVUtil.shared.longvideoapi + videoSendUrl, parames: params, commonParams: commonParams()) { response, _, error, _ in
  37. if error != nil {
  38. completeHander(nil, nil, error?.msg)
  39. return
  40. }
  41. var jsonDict = (response as! [String: Any])
  42. jsonDict["title"] = title
  43. jsonDict["auditStatus"] = 1
  44. jsonDict["uid"] = BFLoginUserInfo.shared.uid
  45. let tempModel = PQVideoListModel(jsonDict: jsonDict)
  46. tempModel.uid = Int(BFLoginUserInfo.shared.uid) ?? 0
  47. tempModel.auditStatus = 1
  48. completeHander(tempModel, jsonDict, nil)
  49. // 发布成功
  50. var extParams: [String: Any] = ["source": (projectId != nil && (projectId?.count ?? 0) > 0) ? "videoCompose" : "videoUpload", "projectId": projectId ?? ""]
  51. if reCreateData != nil {
  52. extParams["projectId"] = reCreateData?.projectId ?? ""
  53. extParams["parentVideoId"] = reCreateData?.videoId ?? ""
  54. extParams["parentProjectId"] = reCreateData?.parentProjectId ?? ""
  55. extParams["rootProjectId"] = reCreateData?.rootProjectId ?? ""
  56. }
  57. BFEventTrackAdaptor.baseReportUpload(businessType: .bt_up_process, objectType: .ot_up_publishSuccess, pageSource: nil, extParams: extParams,commonParams: commonParams())
  58. if projectId != nil {
  59. PQBaseViewModel.reportSendVideo(projectId!, tempModel.uniqueId ?? "", videoFromScene: videoFromScene) { isSuccess, _ in
  60. if !isSuccess {
  61. PQBaseViewModel.reportSendVideo(projectId!, tempModel.uniqueId ?? "", videoFromScene: videoFromScene) { isSuccess, _ in
  62. if !isSuccess {
  63. PQBaseViewModel.reportSendVideo(projectId!, tempModel.uniqueId ?? "", videoFromScene: videoFromScene) { isSuccess, _ in
  64. if !isSuccess {}
  65. }
  66. }
  67. }
  68. }
  69. }
  70. }
  71. if eventTrackData != nil {
  72. eventTrackData?.title = title
  73. eventTrackData?.videoDes = descr
  74. eventTrackData?.videoId = tempModel.uniqueId
  75. eventTrackData?.coverUrl = coverImgPath
  76. BFEventTrackAdaptor.baseReportUpload(logType: .st_log_type_videoProduction, businessType: nil, objectType: nil, pageSource: nil, eventData: eventTrackData?.toParams(),commonParams: commonParams())
  77. }
  78. }
  79. }
  80. /// 修改视频
  81. /// - Parameters:
  82. /// - title: 标题
  83. /// - videoId: 视频id
  84. /// - coverImgPath: 图片地址
  85. /// - descr: 描述
  86. /// - completeHander: <#completeHander description#>
  87. /// - Returns: <#description#>
  88. public class func updateVideo(title: String, videoId: String, coverImgPath: String, descr: String,topicId:Int64? = nil, completeHander: @escaping (_ response:[String:Any]?,_ videoData: PQVideoListModel?, _ msg: String?) -> Void) {
  89. var params : Dictionary<String,Any> = ["title": title, "videoId": videoId, "coverImgPath": coverImgPath, "descr": descr, "viewStatus": 1, "barrageSwitch": 1]
  90. if topicId != nil && (topicId ?? 0) > 0 {
  91. params["topicId"] = topicId!
  92. }
  93. BFNetRequestAdaptor.postRequestData(url: PQENVUtil.shared.longvideoapi + updateVideoUrl, parames: params, commonParams: commonParams()) { response, _, error, _ in
  94. if error != nil {
  95. completeHander(nil,nil, error?.msg)
  96. return
  97. }
  98. // 1015
  99. let tempModel = PQVideoListModel(jsonDict: response as! [String: Any])
  100. tempModel.auditStatus = 1
  101. completeHander(response as? [String: Any],tempModel, nil)
  102. }
  103. }
  104. /// 获取视频封面
  105. /// - Parameters:
  106. /// - videoId: 视频ID
  107. /// - videoPath: 视频地址
  108. /// - totalTime: 总时长
  109. /// - completeHander: <#completeHander description#>
  110. /// - Returns: <#description#>
  111. public class func vodeoCoverImageList(videoId: String, videoPath: String, totalTime: Int, videoHeight: CGFloat, videoWidth: CGFloat, completeHander: @escaping (_ coverImages: [PQUploadModel]?, _ msg: String?) -> Void) {
  112. BFNetRequestAdaptor.postRequestData(url: PQENVUtil.shared.longvideoapi + vodeoCoverImageUrl, parames: ["id": videoId, "videoPath": videoPath, "totalTime": totalTime], commonParams: commonParams()) { response, _, error, _ in
  113. if error != nil {
  114. completeHander(nil, error?.msg)
  115. return
  116. }
  117. var coverImages: [PQUploadModel] = Array<PQUploadModel>.init()
  118. let data: [String: Any]? = response as? [String: Any]
  119. if data != nil, data?.keys.contains("videoCoverImages") ?? false {
  120. let videoCoverImages: [String]? = data?["videoCoverImages"] as? [String]
  121. if videoCoverImages != nil, (videoCoverImages?.count ?? 0) > 0 {
  122. for item in videoCoverImages! {
  123. let tempItem = PQUploadModel()
  124. tempItem.contentMode = .scaleAspectFit
  125. tempItem.videoHeight = videoHeight
  126. tempItem.videoWidth = videoWidth
  127. tempItem.imageUrl = item
  128. coverImages.append(tempItem)
  129. }
  130. }
  131. }
  132. completeHander(coverImages, nil)
  133. }
  134. }
  135. /// - Parameter completeHander: completeHander description
  136. public class func getStsToken(completeHander: @escaping (_ userInfo: [String: Any]?, _ msg: String?) -> Void) {
  137. BFNetRequestAdaptor.postRequestData(url: PQENVUtil.shared.longvideoapi + getStsTokenUrl, parames: ["fileType": "2", "type": 1], commonParams: commonParams()) { response, _, error, _ in
  138. if error != nil {
  139. completeHander(nil, error?.msg)
  140. return
  141. }
  142. completeHander(response as? [String: Any], nil)
  143. }
  144. }
  145. /// 获取OSS
  146. /// - Parameter completeHander: <#completeHander description#>
  147. /// - Returns: <#description#>
  148. public class func ossTempToken(completeHander: @escaping (_ userInfo: [String: Any]?, _ msg: String?) -> Void) {
  149. BFNetRequestAdaptor.postRequestData(url: PQENVUtil.shared.longvideoapi + ossTempTokenUrl, parames: ["type": "2", "fileType": "1"], commonParams: commonParams()) { response, _, _, _ in
  150. completeHander(response as? [String: Any], nil)
  151. }
  152. }
  153. }