46 lines
2.3 KiB
Swift
46 lines
2.3 KiB
Swift
import Foundation
|
|
|
|
/// 景区空境库的只读场次及详情接口,素材下载不回写订单素材状态。
|
|
protocol ScenicMaterialsServing: Sendable {
|
|
/// 按当前景区及筛选分页读取场次。
|
|
@MainActor
|
|
func sessions(query: ScenicMaterialsQuery) async throws -> ScenicMaterialsSessionsResponse
|
|
/// 使用场次身份读取完整片段信息和授权文件地址。
|
|
@MainActor
|
|
func sessionDetail(scenicMediaID: Int) async throws -> ScenicMaterialsSessionDetailResponse
|
|
}
|
|
|
|
/// 朱工景区空境库接口,复用部署环境验证过的 token 鉴权和统一业务包。
|
|
@MainActor
|
|
final class ScenicMaterialsAPI: ScenicMaterialsServing {
|
|
private let client: APIClient
|
|
|
|
/// 注入统一网络客户端,单元测试可使用 MockURLSession。
|
|
init(client: APIClient) { self.client = client }
|
|
|
|
/// 验证请求范围及响应页码,避免拼入其他页或其他筛选的数据。
|
|
func sessions(query: ScenicMaterialsQuery) async throws -> ScenicMaterialsSessionsResponse {
|
|
let response: ScenicMaterialsSessionsResponse = try await client.send(APIRequest(
|
|
method: .get, path: "/api/app/scenic-media/sessions", queryItems: try query.queryItems(),
|
|
redactedLogCategory: "景区空境库"
|
|
))
|
|
guard response.page == query.page, response.pageSize == query.pageSize,
|
|
response.retentionDays == query.retentionDays,
|
|
response.filter.airLineID == (query.airLineID ?? 0),
|
|
response.filter.dateFrom == (query.dateFrom ?? ""), response.filter.dateTo == (query.dateTo ?? "") else {
|
|
throw APIError.decodeFailed("空境库场次与当前查询条件不一致,请刷新重试")
|
|
}
|
|
return response
|
|
}
|
|
|
|
/// 只传文档定义的 scenic_media_id,不传订单、任务或机巢身份。
|
|
func sessionDetail(scenicMediaID: Int) async throws -> ScenicMaterialsSessionDetailResponse {
|
|
guard scenicMediaID > 0 else { throw APIError.networkFailed("空境场次无效,请刷新重试") }
|
|
return try await client.send(APIRequest(
|
|
method: .get, path: "/api/app/scenic-media/session-detail",
|
|
queryItems: [URLQueryItem(name: "scenic_media_id", value: String(scenicMediaID))],
|
|
redactedLogCategory: "景区空境库"
|
|
))
|
|
}
|
|
}
|