PQUploadViewModel.swift 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 UIKit
  9. import BFCommonKit
  10. import BFNetRequestKit
  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. class public func publishVideo(projectId: String?, fileExtensions: String?, title: String, videoPath: String, coverImgPath: String?, descr: String, videoFromScene: videoFromScene, reCreateData: PQReCreateModel?, eventTrackData: PQVideoMakeEventTrackModel?, completeHander: @escaping (_ videoData: PQVideoListModel?, _ jsonDict: [String: Any]?, _ msg: String?) -> Void) {
  23. BFLog(message: "AKAKAAKprojectId is\(String(describing: projectId)) videoFromScene is \(videoFromScene)")
  24. var params : Dictionary<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. BFNetRequestAdaptor.postRequestData(url: PQENVUtil.shared.longvideoapi + videoSendUrl, parames: params, commonParams: commonParams()) { response, _, error, _ in
  29. if error != nil {
  30. completeHander(nil, nil, error?.msg)
  31. return
  32. }
  33. var jsonDict = (response as! [String: Any])
  34. jsonDict["title"] = title
  35. jsonDict["auditStatus"] = 1
  36. jsonDict["uid"] = BFLoginUserInfo.shared.uid
  37. let tempModel = PQVideoListModel(jsonDict: jsonDict)
  38. tempModel.uid = Int(BFLoginUserInfo.shared.uid) ?? 0
  39. tempModel.auditStatus = 1
  40. completeHander(tempModel, jsonDict, nil)
  41. // 发布成功
  42. var extParams: [String: Any] = ["source": (projectId != nil && (projectId?.count ?? 0) > 0) ? "videoCompose" : "videoUpload", "projectId": projectId ?? ""]
  43. if reCreateData != nil {
  44. extParams["projectId"] = reCreateData?.projectId ?? ""
  45. extParams["parentVideoId"] = reCreateData?.videoId ?? ""
  46. extParams["parentProjectId"] = reCreateData?.parentProjectId ?? ""
  47. extParams["rootProjectId"] = reCreateData?.rootProjectId ?? ""
  48. }
  49. PQEventTrackViewModel.baseReportUpload(businessType: .bt_up_process, objectType: .ot_up_publishSuccess, pageSource: nil, extParams: extParams, remindmsg: "上传相关")
  50. if projectId != nil {
  51. PQBaseViewModel.reportSendVideo(projectId!, tempModel.uniqueId ?? "",videoFromScene: videoFromScene) { isSuccess, _ in
  52. if !isSuccess {
  53. PQBaseViewModel.reportSendVideo(projectId!, tempModel.uniqueId ?? "",videoFromScene: videoFromScene) { isSuccess, _ in
  54. if !isSuccess {
  55. PQBaseViewModel.reportSendVideo(projectId!, tempModel.uniqueId ?? "",videoFromScene: videoFromScene) { isSuccess, _ in
  56. if !isSuccess {}
  57. }
  58. }
  59. }
  60. }
  61. }
  62. }
  63. if eventTrackData != nil {
  64. eventTrackData?.title = title
  65. eventTrackData?.videoDes = descr
  66. eventTrackData?.videoId = tempModel.uniqueId
  67. eventTrackData?.coverUrl = coverImgPath
  68. PQEventTrackViewModel.baseReportUpload(logType: .st_log_type_videoProduction, businessType: nil, objectType: nil, pageSource: nil, eventData: eventTrackData?.toParams(), remindmsg: "创作工具埋点上报")
  69. }
  70. }
  71. }
  72. /// 修改视频
  73. /// - Parameters:
  74. /// - title: 标题
  75. /// - videoId: 视频id
  76. /// - coverImgPath: 图片地址
  77. /// - descr: 描述
  78. /// - completeHander: <#completeHander description#>
  79. /// - Returns: <#description#>
  80. public class func updateVideo(title: String, videoId: String, coverImgPath: String, descr: String, completeHander: @escaping (_ videoData: PQVideoListModel?, _ msg: String?) -> Void) {
  81. BFNetRequestAdaptor.postRequestData(url: PQENVUtil.shared.longvideoapi + updateVideoUrl, parames: ["title": title, "videoId": videoId, "coverImgPath": coverImgPath, "descr": descr, "viewStatus": 1, "barrageSwitch": 1], commonParams: commonParams()) { response, _, error, _ in
  82. if error != nil {
  83. completeHander(nil, error?.msg)
  84. return
  85. }
  86. // 1015
  87. let tempModel = PQVideoListModel(jsonDict: response as! [String: Any])
  88. tempModel.auditStatus = 1
  89. completeHander(tempModel, nil)
  90. }
  91. }
  92. /// 获取视频封面
  93. /// - Parameters:
  94. /// - videoId: 视频ID
  95. /// - videoPath: 视频地址
  96. /// - totalTime: 总时长
  97. /// - completeHander: <#completeHander description#>
  98. /// - Returns: <#description#>
  99. class public func vodeoCoverImageList(videoId: String, videoPath: String, totalTime: Int, videoHeight: CGFloat, videoWidth: CGFloat, completeHander: @escaping (_ coverImages: [PQUploadModel]?, _ msg: String?) -> Void) {
  100. BFNetRequestAdaptor.postRequestData(url: PQENVUtil.shared.longvideoapi + vodeoCoverImageUrl, parames: ["id": videoId, "videoPath": videoPath, "totalTime": totalTime], commonParams: commonParams()) { response, _, error, _ in
  101. if error != nil {
  102. completeHander(nil, error?.msg)
  103. return
  104. }
  105. var coverImages: [PQUploadModel] = Array<PQUploadModel>.init()
  106. let data: [String: Any]? = response as? [String: Any]
  107. if data != nil, data?.keys.contains("videoCoverImages") ?? false {
  108. let videoCoverImages: [String]? = data?["videoCoverImages"] as? [String]
  109. if videoCoverImages != nil, (videoCoverImages?.count ?? 0) > 0 {
  110. for item in videoCoverImages! {
  111. let tempItem = PQUploadModel()
  112. tempItem.contentMode = .scaleAspectFit
  113. tempItem.videoHeight = videoHeight
  114. tempItem.videoWidth = videoWidth
  115. tempItem.imageUrl = item
  116. coverImages.append(tempItem)
  117. }
  118. }
  119. }
  120. completeHander(coverImages, nil)
  121. }
  122. }
  123. }