114 lines
3.6 KiB
Swift
114 lines
3.6 KiB
Swift
//
|
|
// SPVideoAPI.swift
|
|
// ShortPlay
|
|
//
|
|
// Created by 曾觉新 on 2025/4/10.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class SPVideoAPI: NSObject {
|
|
|
|
///获取视频详情
|
|
static func requestVideoDetail(videoId: String?, shortPlayId: String, completer: ((_ model: SPVideoDetailModel?) -> Void)?) {
|
|
var parameters: [String : Any] = [
|
|
"short_play_id" : shortPlayId
|
|
]
|
|
|
|
if let videoId = videoId {
|
|
parameters["video_id"] = videoId
|
|
}
|
|
var param = SPNetworkParameters(path: "/getVideoDetails")
|
|
param.method = .get
|
|
param.parameters = parameters
|
|
|
|
SPNetwork.request(parameters: param) { (response: SPNetworkResponse<SPVideoDetailModel>) in
|
|
completer?(response.data)
|
|
}
|
|
}
|
|
|
|
///创建播放记录
|
|
static func requestRequestVideoPlayHistory(videoId: String, shortPlayId: String) {
|
|
var param = SPNetworkParameters(path: "/createHistory")
|
|
param.isLoding = false
|
|
param.isToast = false
|
|
param.parameters = [
|
|
"video_id" : videoId,
|
|
"short_play_id" : shortPlayId
|
|
]
|
|
|
|
SPNetwork.request(parameters: param) { (response: SPNetworkResponse<String>) in
|
|
|
|
}
|
|
}
|
|
|
|
///收藏短剧
|
|
static func requestCollectShort(isCollect: Bool, shortPlayId: String, videoId: String?, success: (() -> Void)?, failure: (() -> Void)? = nil) {
|
|
let path: String
|
|
if isCollect {
|
|
path = "/collect"
|
|
} else {
|
|
path = "/cancelCollect"
|
|
}
|
|
|
|
var parameters: [String : Any] = [
|
|
"short_play_id" : shortPlayId,
|
|
]
|
|
|
|
if let videoId = videoId {
|
|
parameters["video_id"] = videoId
|
|
}
|
|
|
|
var param = SPNetworkParameters(path: path)
|
|
param.isLoding = true
|
|
param.parameters = parameters
|
|
|
|
SPNetwork.request(parameters: param) { (response: SPNetworkResponse<String>) in
|
|
if response.code == SPNetworkCodeSucceed {
|
|
success?()
|
|
NotificationCenter.default.post(name: SPVideoAPI.updateShortCollectStateNotification, object: nil, userInfo: [
|
|
"state" : isCollect,
|
|
"id" : shortPlayId,
|
|
])
|
|
} else {
|
|
failure?()
|
|
}
|
|
}
|
|
}
|
|
|
|
///收藏列表
|
|
static func requestCollectList(page: Int, completer: ((_ listModel: SPListModel<SPShortModel>?) -> Void)?) {
|
|
var param = SPNetworkParameters(path: "/myCollections")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"current_page" : page,
|
|
"page_size" : 20
|
|
]
|
|
|
|
SPNetwork.request(parameters: param) { (response: SPNetworkResponse<SPListModel<SPShortModel>>) in
|
|
completer?(response.data)
|
|
}
|
|
}
|
|
|
|
///历史记录列表
|
|
static func requestPlayHistoryList(page: Int, completer: ((_ listModel: SPListModel<SPShortModel>?) -> Void)?) {
|
|
var param = SPNetworkParameters(path: "/myHistorys")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"current_page" : page,
|
|
"page_size" : 20
|
|
]
|
|
|
|
SPNetwork.request(parameters: param) { (response: SPNetworkResponse<SPListModel<SPShortModel>>) in
|
|
completer?(response.data)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension SPVideoAPI {
|
|
///更新短剧关注状态 [ "state" : isCollect, "id" : shortPlayId,]
|
|
@objc static let updateShortCollectStateNotification = NSNotification.Name(rawValue: "SPVideoAPI.updateShortCollectStateNotification")
|
|
|
|
}
|