123 lines
4.4 KiB
Swift
123 lines
4.4 KiB
Swift
//
|
|
// SRHomeApi.swift
|
|
// SynthReel
|
|
//
|
|
// Created by 湖北秦九 on 2025/11/14.
|
|
// Copyright © 2025 SR. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import Alamofire
|
|
|
|
|
|
struct SRHomeApi {
|
|
|
|
static func requestCategoryList() async -> [SRCategoryModel]? {
|
|
|
|
await withCheckedContinuation { continuation in
|
|
var param = SRNetwork.Parameters(path: "/getCategories")
|
|
param.method = .get
|
|
SRNetwork.request(parameters: param) { (response: SRNetwork.Response<SRNetwork.List<SRCategoryModel>>) in
|
|
continuation.resume(returning: response.data?.list)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
static func requestHomeModulesData() async -> [SRHomeModuleItem]? {
|
|
await withCheckedContinuation { continuation in
|
|
var param = SRNetwork.Parameters(path: "/home/all-modules")
|
|
param.method = .get
|
|
SRNetwork.request(parameters: param) { (response: SRNetwork.Response<SRNetwork.List<SRHomeModuleItem>>) in
|
|
continuation.resume(returning: response.data?.list)
|
|
}
|
|
}
|
|
}
|
|
|
|
static func requestCategoryVideoData(_ id: String, page: Int) async -> [SRShortModel]? {
|
|
await withCheckedContinuation { continuation in
|
|
var param = SRNetwork.Parameters(path: "/videoList")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"category_id" : id,
|
|
"current_page" : page,
|
|
"page_size" : 20
|
|
]
|
|
SRNetwork.request(parameters: param) { (response: SRNetwork.Response<SRNetwork.List<SRShortModel>>) in
|
|
continuation.resume(returning: response.data?.list)
|
|
}
|
|
}
|
|
}
|
|
|
|
static func requestHotSearchData() async -> [SRShortModel]? {
|
|
await withCheckedContinuation { continuation in
|
|
var param = SRNetwork.Parameters(path: "/search/hots")
|
|
param.method = .get
|
|
|
|
SRNetwork.request(parameters: param) { (response: SRNetwork.Response<SRNetwork.List<SRShortModel>>) in
|
|
continuation.resume(returning: response.data?.list)
|
|
}
|
|
}
|
|
}
|
|
|
|
static func requestSearch(_ text: String) async -> [SRShortModel]? {
|
|
await withCheckedContinuation { continuation in
|
|
var param = SRNetwork.Parameters(path: "/search")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"search" : text
|
|
]
|
|
|
|
SRNetwork.request(parameters: param) { (response: SRNetwork.Response<SRNetwork.List<SRShortModel>>) in
|
|
continuation.resume(returning: response.data?.list)
|
|
}
|
|
}
|
|
}
|
|
|
|
static func requestHomeRecommendData(page: Int) async -> [SRShortModel]? {
|
|
await withCheckedContinuation { continuation in
|
|
var param = SRNetwork.Parameters(path: "/getRecommands")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"page_size" : 20,
|
|
"current_page" : page
|
|
]
|
|
|
|
SRNetwork.request(parameters: param) { (response: SRNetwork.Response<SRNetwork.List<SRShortModel>>) in
|
|
continuation.resume(returning: response.data?.list)
|
|
}
|
|
}
|
|
}
|
|
|
|
static func requestHistoryData(page: Int) async -> [SRShortModel]? {
|
|
await withCheckedContinuation { continuation in
|
|
var param = SRNetwork.Parameters(path: "/myHistorys")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"page_size" : 20,
|
|
"current_page" : page
|
|
]
|
|
|
|
SRNetwork.request(parameters: param) { (response: SRNetwork.Response<SRNetwork.List<SRShortModel>>) in
|
|
continuation.resume(returning: response.data?.list)
|
|
}
|
|
}
|
|
}
|
|
|
|
static func requestFavoritesData(page: Int) async -> [SRShortModel]? {
|
|
await withCheckedContinuation { continuation in
|
|
var param = SRNetwork.Parameters(path: "/myCollections")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"page_size" : 20,
|
|
"current_page" : page
|
|
]
|
|
|
|
SRNetwork.request(parameters: param) { (response: SRNetwork.Response<SRNetwork.List<SRShortModel>>) in
|
|
continuation.resume(returning: response.data?.list)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|