新增 OSS 上传与 Kingfisher 图片加载支持
This commit is contained in:
41
suixinkan/Core/Upload/UploadAPI.swift
Normal file
41
suixinkan/Core/Upload/UploadAPI.swift
Normal file
@ -0,0 +1,41 @@
|
||||
//
|
||||
// UploadAPI.swift
|
||||
// suixinkan
|
||||
//
|
||||
// Created by Codex on 2026/6/22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Observation
|
||||
|
||||
/// OSS 配置服务协议,抽象 STS token 获取能力,便于上传服务测试替换。
|
||||
@MainActor
|
||||
protocol OSSConfigServing {
|
||||
/// 获取指定 bucket 的阿里云 OSS 临时上传配置。
|
||||
func aliyunOSSBucket(bucket: String) async throws -> AliyunOSSResponse
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Observable
|
||||
/// 上传 API,封装文件上传前需要的服务端配置接口。
|
||||
final class UploadAPI {
|
||||
@ObservationIgnored private let client: APIClient
|
||||
|
||||
/// 初始化上传 API,并注入共享网络客户端。
|
||||
init(client: APIClient) {
|
||||
self.client = client
|
||||
}
|
||||
|
||||
/// 获取指定 bucket 的阿里云 OSS 临时上传配置。
|
||||
func aliyunOSSBucket(bucket: String = "vipsky") async throws -> AliyunOSSResponse {
|
||||
try await client.send(
|
||||
APIRequest(
|
||||
method: .get,
|
||||
path: "/api/app/config/get-sts-token",
|
||||
queryItems: [URLQueryItem(name: "bucket", value: bucket)]
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
extension UploadAPI: OSSConfigServing {}
|
||||
Reference in New Issue
Block a user