feat: add live module and optimize report list

This commit is contained in:
2026-07-08 14:25:14 +08:00
parent 8ca8bcf948
commit 4a78a0c21a
14 changed files with 3712 additions and 102 deletions

View File

@ -0,0 +1,194 @@
//
// LiveAPI.swift
// suixinkan
//
import Foundation
/// manual-live view-album
@MainActor
protocol LiveServing {
///
func liveList(scenicId: String, page: Int, pageSize: Int) async throws -> LiveListResponse
///
func liveDetail(liveId: Int) async throws -> LiveItem
///
func createLive(scenicId: String, title: String, coverImg: String) async throws
///
func startLive(liveId: Int) async throws
///
func stopLive(liveId: Int) async throws
///
func finishLive(liveId: Int) async throws
///
func setPushMode(liveId: Int, mode: Int) async throws
///
func albumList(scenicId: String, startTime: String?, endTime: String?, page: Int, pageSize: Int) async throws -> LiveAlbumFolderListResponse
///
func createAlbumFolder(scenicId: String, name: String, items: [LiveAlbumFile]) async throws
///
func deleteAlbumFolder(folderId: Int) async throws
///
func albumFolderDetail(folderId: Int) async throws -> LiveAlbumFolder
///
func deleteAlbumFile(folderId: Int, fileId: Int) async throws
}
/// API Android `NetworkApi` alive/manual-live view-album
@MainActor
final class LiveAPI: LiveServing {
private let client: APIClient
/// API
init(client: APIClient) {
self.client = client
}
///
func liveList(scenicId: String, 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: scenicId),
URLQueryItem(name: "page", value: String(max(page, 1))),
URLQueryItem(name: "page_size", value: String(max(pageSize, 1))),
]
)
)
}
///
func liveDetail(liveId: Int) async throws -> LiveItem {
try await client.send(
APIRequest(
method: .get,
path: "/api/app/manual-live/detail",
queryItems: [URLQueryItem(name: "live_id", value: String(liveId))]
)
)
}
///
func createLive(scenicId: String, title: String, coverImg: String) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(
method: .post,
path: "/api/app/manual-live/create",
body: LiveCreateRequest(scenicId: scenicId, title: title, coverImg: coverImg)
)
)
}
///
func startLive(liveId: Int) async throws {
try await controlLive(path: "/api/app/manual-live/start", liveId: liveId)
}
///
func stopLive(liveId: Int) async throws {
try await controlLive(path: "/api/app/manual-live/stop", liveId: liveId)
}
///
func finishLive(liveId: Int) async throws {
try await controlLive(path: "/api/app/manual-live/finish", liveId: liveId)
}
///
func setPushMode(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 albumList(
scenicId: String,
startTime: String? = nil,
endTime: String? = nil,
page: Int = 1,
pageSize: Int = 10
) async throws -> LiveAlbumFolderListResponse {
var items = [
URLQueryItem(name: "scenic_id", value: scenicId),
URLQueryItem(name: "page", value: String(max(page, 1))),
URLQueryItem(name: "page_size", value: String(max(pageSize, 1))),
]
if let startTime, !startTime.isEmpty {
items.append(URLQueryItem(name: "start_time", value: startTime))
}
if let endTime, !endTime.isEmpty {
items.append(URLQueryItem(name: "end_time", value: endTime))
}
return try await client.send(
APIRequest(method: .get, path: "/api/app/view-album/folders", queryItems: items)
)
}
///
func createAlbumFolder(scenicId: String, name: String, items: [LiveAlbumFile]) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(
method: .post,
path: "/api/app/view-album/create-folder",
body: LiveAlbumFolderCreateRequest(scenicId: scenicId, name: name, items: items)
)
)
}
///
func deleteAlbumFolder(folderId: Int) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(
method: .post,
path: "/api/app/view-album/delete-folder",
body: LiveAlbumFolderDeleteRequest(folderId: folderId)
)
)
}
///
func albumFolderDetail(folderId: Int) async throws -> LiveAlbumFolder {
try await client.send(
APIRequest(
method: .get,
path: "/api/app/view-album/folder-detail",
queryItems: [URLQueryItem(name: "folder_id", value: String(folderId))]
)
)
}
///
func deleteAlbumFile(folderId: Int, fileId: Int) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(
method: .post,
path: "/api/app/view-album/delete-files",
body: LiveAlbumFileDeleteRequest(folderId: folderId, fileIds: [fileId])
)
)
}
private func controlLive(path: String, liveId: Int) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(method: .post, path: path, body: LiveControlRequest(liveId: liveId))
)
}
}