Files
suixinkan_ios_uikit/suixinkan_ios/Features/Live/API/LiveAPI.swift
2026-06-26 14:33:31 +08:00

160 lines
5.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// LiveAPI.swift
// suixinkan
//
// Created by Codex on 2026/6/25.
//
import Foundation
///
@MainActor
protocol LiveServing {
func liveList(scenicId: Int, page: Int, pageSize: Int) async throws -> LiveListResponse
func liveDetail(liveId: Int) async throws -> LiveEntity
func liveCreate(_ request: LiveCreateRequest) async throws
func liveStart(liveId: Int) async throws
func liveStop(liveId: Int) async throws
func liveFinish(liveId: Int) async throws
func liveSetPushMode(liveId: Int, mode: Int) async throws
func liveAlbumList(scenicId: Int, startTime: String?, endTime: String?, page: Int, pageSize: Int) async throws -> LiveAlbumFolderListResponse
func liveAlbumCreateFolder(_ request: LiveAlbumCreateFolderRequest) async throws
func liveAlbumDeleteFolder(folderId: Int) async throws
func liveAlbumFolderDetail(folderId: Int) async throws -> LiveAlbumFolderItem
func liveAlbumDeleteFiles(folderId: Int, fileIds: [Int]) async throws
}
@MainActor
/// API
final class LiveAPI {
private let client: APIClient
/// API
init(client: APIClient) {
self.client = client
}
///
func liveList(scenicId: Int, page: Int = 1, pageSize: Int = 10) async throws -> LiveListResponse {
try await client.send(
APIRequest(
method: .get,
path: "/api/app/manual-live/list",
queryItems: [
URLQueryItem(name: "scenic_id", value: String(scenicId)),
URLQueryItem(name: "page", value: String(max(page, 1))),
URLQueryItem(name: "page_size", value: String(max(pageSize, 1)))
]
)
)
}
///
func liveDetail(liveId: Int) async throws -> LiveEntity {
try await client.send(
APIRequest(
method: .get,
path: "/api/app/manual-live/detail",
queryItems: [URLQueryItem(name: "live_id", value: String(liveId))]
)
)
}
///
func liveCreate(_ request: LiveCreateRequest) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(method: .post, path: "/api/app/manual-live/create", body: request)
)
}
///
func liveStart(liveId: Int) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(method: .post, path: "/api/app/manual-live/start", body: LiveControlRequest(liveId: liveId))
)
}
///
func liveStop(liveId: Int) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(method: .post, path: "/api/app/manual-live/stop", body: LiveControlRequest(liveId: liveId))
)
}
///
func liveFinish(liveId: Int) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(method: .post, path: "/api/app/manual-live/finish", body: LiveControlRequest(liveId: liveId))
)
}
///
func liveSetPushMode(liveId: Int, mode: Int) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(method: .post, path: "/api/app/manual-live/set-push-mode", body: LivePushModeRequest(liveId: liveId, manualPushMode: mode))
)
}
///
func liveAlbumList(
scenicId: Int,
startTime: String? = nil,
endTime: String? = nil,
page: Int = 1,
pageSize: Int = 10
) async throws -> LiveAlbumFolderListResponse {
var queryItems = [
URLQueryItem(name: "scenic_id", value: String(scenicId)),
URLQueryItem(name: "page", value: String(max(page, 1))),
URLQueryItem(name: "page_size", value: String(max(pageSize, 1)))
]
if let startTime = startTime?.liveTrimmed, !startTime.isEmpty {
queryItems.append(URLQueryItem(name: "start_time", value: startTime))
}
if let endTime = endTime?.liveTrimmed, !endTime.isEmpty {
queryItems.append(URLQueryItem(name: "end_time", value: endTime))
}
return try await client.send(
APIRequest(method: .get, path: "/api/app/view-album/folders", queryItems: queryItems)
)
}
///
func liveAlbumCreateFolder(_ request: LiveAlbumCreateFolderRequest) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(method: .post, path: "/api/app/view-album/create-folder", body: request)
)
}
///
func liveAlbumDeleteFolder(folderId: Int) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(method: .post, path: "/api/app/view-album/delete-folder", body: LiveAlbumDeleteFolderRequest(folderId: folderId))
)
}
///
func liveAlbumFolderDetail(folderId: Int) async throws -> LiveAlbumFolderItem {
try await client.send(
APIRequest(
method: .get,
path: "/api/app/view-album/folder-detail",
queryItems: [URLQueryItem(name: "folder_id", value: String(folderId))]
)
)
}
///
func liveAlbumDeleteFiles(folderId: Int, fileIds: [Int]) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(
method: .post,
path: "/api/app/view-album/delete-files",
body: LiveAlbumDeleteFilesRequest(folderId: folderId, fileIds: fileIds)
)
)
}
}
extension LiveAPI: LiveServing {}