PQUploadViewModel.swift 7.4 KB

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