Files
suixinkan_ios_new/suixinkan/Features/Live/API/LiveAPI.swift
汉秋 fcb692b56a 新增直播模块,包含推流管理与相册流程
将直播推流管理与直播相册从首页占位页迁移为完整实现,包含 alive album OSS 上传、首页路由与单元测试。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-25 14:38:52 +08:00

162 lines
5.9 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
import Observation
///
@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
@Observable
/// API
final class LiveAPI {
@ObservationIgnored 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 {}