Files
e-party-iOS/yana/APIs/APIEndpoints.swift
edwinQQQ 12bb4a5f8c feat: 更新Podfile和Podfile.lock,添加最新动态API文档和相关功能
- 在Podfile中添加Alamofire依赖,并更新Podfile.lock以反映更改。
- 新增动态内容API文档,详细描述`dynamic/square/latestDynamics`接口的请求参数、响应数据结构及示例。
- 实现动态内容的模型和API请求结构,支持获取最新动态列表。
- 更新FeedView和HomeView以集成动态内容展示,增强用户体验。
- 添加动态卡片组件,展示用户动态信息及互动功能。
2025-07-11 20:18:24 +08:00

134 lines
4.5 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.

import Foundation
// MARK: - API Endpoints
/// API
///
/// API
/// 使
///
/// case
///
/// 使
/// ```swift
/// let configPath = APIEndpoint.config.path // "/client/config"
/// ```
enum APIEndpoint: String, CaseIterable {
case config = "/client/config"
case configInit = "/client/init"
case login = "/oauth/token"
case ticket = "/oauth/ticket"
case emailGetCode = "/email/getCode" //
case latestDynamics = "/dynamic/square/latestDynamics" //
// Web
case userAgreement = "/modules/rule/protocol.html"
case privacyPolicy = "/modules/rule/privacy-wap.html"
var path: String {
return self.rawValue
}
}
// MARK: - API Configuration
/// API
///
/// API
/// -
/// -
/// -
/// -
///
///
/// -
/// -
/// -
struct APIConfiguration {
static var baseURL: String { AppConfig.baseURL }
static let timeout: TimeInterval = 30.0
static let maxDataSize: Int = 50 * 1024 * 1024 // 50MB
/// URL
/// - Parameter endpoint: API
/// - Returns: URL
static func fullURL(for endpoint: APIEndpoint) -> String {
return baseURL + endpoint.path
}
/// URL
/// - Parameter endpoint: API
/// - Returns: URL nil
static func url(for endpoint: APIEndpoint) -> URL? {
return URL(string: fullURL(for: endpoint))
}
/// Web URL
/// - Parameter endpoint: API
/// - Returns: Web URL
static func fullWebURL(for endpoint: APIEndpoint) -> String {
return baseURL + AppConfig.webPathPrefix + endpoint.path
}
/// Web URL
/// - Parameter endpoint: API
/// - Returns: Web URL nil
static func webURL(for endpoint: APIEndpoint) -> URL? {
return URL(string: fullWebURL(for: endpoint))
}
///
///
/// API
/// - Content-Type Accept
/// -
/// -
/// -
///
///
static var defaultHeaders: [String: String] {
var headers = [
"Content-Type": "application/json",
"Accept": "application/json",
"Accept-Encoding": "gzip, br",
"Accept-Language": Locale.current.languageCode ?? "en",
"App-Version": Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "1.0.0",
"User-Agent": "YuMi/20.20.61 (iPhone; iOS 16.4; Scale/2.00)"
]
// headers
let authStatus = UserInfoManager.checkAuthenticationStatus()
if authStatus.canAutoLogin {
// headers AccountModel
if let userId = UserInfoManager.getCurrentUserId() {
headers["pub_uid"] = userId
#if DEBUG
debugInfo("🔐 添加认证 header: pub_uid = \(userId)")
#endif
}
if let userTicket = UserInfoManager.getCurrentUserTicket() {
headers["pub_ticket"] = userTicket
#if DEBUG
debugInfo("🔐 添加认证 header: pub_ticket = \(userTicket.prefix(20))...")
#endif
}
} else {
#if DEBUG
debugInfo("🔐 跳过认证 header 添加 - 认证状态: \(authStatus.description)")
#endif
}
return headers
}
}
// MARK: - Request Models
struct LoginRequest: Codable {
let username: String
let password: String
}
// MARK: - Empty Request
struct EmptyRequest: Codable {}