241 lines
8.5 KiB
Swift
241 lines
8.5 KiB
Swift
//
|
|
// NRNovelAPI.swift
|
|
// ReaderHive
|
|
//
|
|
// Created by 湖北秦九 on 2025/11/25.
|
|
//
|
|
|
|
import UIKit
|
|
import Alamofire
|
|
|
|
|
|
struct NRNovelAPI {
|
|
|
|
static func requestDetail(_ id: String) async -> (NRNovelModel?, Int?, String?) {
|
|
await withCheckedContinuation { continuation in
|
|
var param = NRNetwork.Parameters(path: "/novel/getDetails")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"short_play_id" : id,
|
|
]
|
|
NRNetwork.request(parameters: param) { (response: NRNetwork.Response<NRNovelModel>) in
|
|
if response.isSuccess {
|
|
continuation.resume(returning:(response.data, response.code, response.msg))
|
|
} else {
|
|
continuation.resume(returning:(nil, response.code, response.msg))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
///给小说打分
|
|
static func requestRateScore(_ id: String, stars: CGFloat) async -> Bool {
|
|
|
|
await withCheckedContinuation { continuation in
|
|
var param = NRNetwork.Parameters(path: "/novel/rateScore")
|
|
param.isLoding = true
|
|
param.parameters = [
|
|
"short_play_id" : id,
|
|
"stars_num" : floor(stars)
|
|
]
|
|
|
|
NRNetwork.request(parameters: param) { (response: NRNetwork.Response<NRNovelModel>) in
|
|
if response.isSuccess {
|
|
continuation.resume(returning: true)
|
|
} else {
|
|
continuation.resume(returning: false)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
///上报阅读记录
|
|
static func requestUploadRecord(_ id: String, chapterId: String) {
|
|
var param = NRNetwork.Parameters(path: "/novel/watchProgressReport")
|
|
param.isToast = false
|
|
param.parameters = [
|
|
"short_play_id" : id,
|
|
"short_play_video_id" : chapterId
|
|
]
|
|
|
|
NRNetwork.request(parameters: param) { (response: NRNetwork.Response<String>) in
|
|
|
|
}
|
|
}
|
|
|
|
///查询章节列表
|
|
static func requestChapterCatalogList(id: String,
|
|
page: Int = 1,
|
|
pageSize: Int = 10000,
|
|
sort: String = "asc") async -> [NRReadChapterCatalogModel]? {
|
|
await withCheckedContinuation { continuation in
|
|
var param = NRNetwork.Parameters(path: "/novel/getChapterList")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"short_play_id" : id,
|
|
"order_by" : sort,
|
|
"current_page" : page,
|
|
"page_size" : pageSize
|
|
]
|
|
NRNetwork.request(parameters: param) { (response: NRNetwork.Response<NRNetwork.List<NRReadChapterCatalogModel>>) in
|
|
if response.isSuccess {
|
|
continuation.resume(returning: response.data?.list)
|
|
} else {
|
|
continuation.resume(returning: nil)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
///查询章节数据 10011 金币不足 10005 提示
|
|
static func requestChapterData(novelId: String, chapterId: String) async -> (NRReadChapterModel?, Int?) {
|
|
await withCheckedContinuation { continuation in
|
|
var param = NRNetwork.Parameters(path: "/novel/getChapterInfo")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"short_play_id" : novelId,
|
|
"short_play_video_id" : chapterId,
|
|
]
|
|
NRNetwork.request(parameters: param) { (response: NRNetwork.Response<NRReadChapterModel>) in
|
|
if response.isSuccess {
|
|
continuation.resume(returning: (response.data, response.code))
|
|
} else {
|
|
continuation.resume(returning: (nil, response.code))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
static func requestDetailRecommandData() async -> [NRNovelModel]? {
|
|
|
|
await withCheckedContinuation { continuation in
|
|
var param = NRNetwork.Parameters(path: "/getDetailsRecommand")
|
|
param.method = .get
|
|
|
|
NRNetwork.request(parameters: param) { (response: NRNetwork.Response<NRNetwork.List<NRNovelModel>>) in
|
|
if response.isSuccess {
|
|
continuation.resume(returning: response.data?.list)
|
|
} else {
|
|
continuation.resume(returning: nil)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@discardableResult
|
|
static func requestCollect(isCollect: Bool, id: String, chapterId: String? = nil) async -> Bool {
|
|
await withCheckedContinuation { continuation in
|
|
let path: String
|
|
if isCollect {
|
|
path = "/collect"
|
|
} else {
|
|
path = "/cancelCollect"
|
|
}
|
|
var param = NRNetwork.Parameters(path: path)
|
|
param.method = .post
|
|
param.isLoding = true
|
|
param.parameters = [
|
|
"short_play_id" : id,
|
|
"video_id" : chapterId ?? 0
|
|
]
|
|
|
|
NRNetwork.request(parameters: param) { (response: NRNetwork.Response<String>) in
|
|
if response.isSuccess {
|
|
continuation.resume(returning: true)
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
|
NotificationCenter.default.post(name: NRNovelAPI.updateCollectStateNotification, object: nil, userInfo: [
|
|
"state" : isCollect,
|
|
"id" : id,
|
|
])
|
|
}
|
|
|
|
} else {
|
|
continuation.resume(returning: false)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static func requestCollectList(page: Int) async -> [NRNovelModel]? {
|
|
|
|
await withCheckedContinuation { continuation in
|
|
var param = NRNetwork.Parameters(path: "/myCollections")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"current_page" : page,
|
|
"page_size" : 20
|
|
]
|
|
|
|
NRNetwork.request(parameters: param) { (response: NRNetwork.Response<NRNetwork.List<NRNovelModel>>) in
|
|
if response.isSuccess {
|
|
continuation.resume(returning: response.data?.list)
|
|
} else {
|
|
continuation.resume(returning: nil)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static func requestHistoryList(page: Int) async -> [NRNovelModel]? {
|
|
await withCheckedContinuation { continuation in
|
|
var param = NRNetwork.Parameters(path: "/myHistorys")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"current_page" : page,
|
|
"page_size" : 20
|
|
]
|
|
|
|
NRNetwork.request(parameters: param) { (response: NRNetwork.Response<NRNetwork.List<NRNovelModel>>) in
|
|
if response.isSuccess {
|
|
continuation.resume(returning: response.data?.list)
|
|
} else {
|
|
continuation.resume(returning: nil)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static func requestShowRecommendPop(id: String) async -> NRShowRecommendPop? {
|
|
await withCheckedContinuation { continuation in
|
|
var param = NRNetwork.Parameters(path: "/novel/isShowRecommendPopUp")
|
|
param.method = .get
|
|
param.isLoding = true
|
|
param.parameters = [
|
|
"short_play_id" : id,
|
|
]
|
|
|
|
NRNetwork.request(parameters: param) { (response: NRNetwork.Response<NRShowRecommendPop>) in
|
|
|
|
if response.isSuccess {
|
|
continuation.resume(returning: response.data)
|
|
} else {
|
|
continuation.resume(returning: nil)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static func requestConfirmRecommend(_ id: String) {
|
|
var param = NRNetwork.Parameters(path: "/novel/confirmRecommend")
|
|
param.method = .get
|
|
param.isLoding = false
|
|
param.isToast = false
|
|
param.parameters = [
|
|
"short_play_id" : id,
|
|
]
|
|
NRNetwork.request(parameters: param) { (response: NRNetwork.Response<String>) in
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
extension NRNovelAPI {
|
|
///更新关注状态 [ "state" : isCollect, "id" : shortPlayId,]
|
|
static let updateCollectStateNotification = Notification.Name(rawValue: "NRNovelAPI.updateCollectStateNotification")
|
|
|
|
}
|