Files
e-party-iOS/yana/APIs/APIEndpoints.swift
edwinQQQ 567b1f3fd9 feat: 全面替换硬编码文本并修复编译错误
- 替换多个视图中的硬编码文本为本地化字符串,增强多语言支持。
- 修复编译错误,包括删除重复文件和修复作用域问题。
- 更新本地化文件,新增40+个本地化键值对,确保文本正确显示。
- 添加语言切换测试区域,验证文本实时更新功能。
2025-07-29 15:31:19 +08:00

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

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" //
case tcToken = "/tencent/cos/getToken" // COS Token
case publishFeed = "/dynamic/square/publish" //
case getUserInfo = "/user/get" //
case getMyDynamic = "/dynamic/getMyDynamic"
case updateUser = "/user/v2/update" //
case dynamicLike = "/dynamic/like" // /
case deleteDynamic = "/dynamic/delete" //
// Web
case userAgreement = "/modules/rule/protocol.html"
case privacyPolicy = "/modules/rule/privacy-wap.html"
case deactivateAccount = "/modules/logout/confirm.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 func defaultHeaders() async -> [String: String] {
var headers = [
"Content-Type": "application/json",
"Accept": "application/json",
"Accept-Encoding": "gzip, br",
"Accept-Language": Locale.current.language.languageCode?.identifier ?? "en",
"App-Version": Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "1.0.0",
"User-Agent": "YuMi/20.20.61 (iPhone; iOS 17+; Scale/2.00)"
]
// headers
let authStatus = await UserInfoManager.checkAuthenticationStatus()
if authStatus.canAutoLogin {
// headers AccountModel
if let userId = await UserInfoManager.getCurrentUserId() {
headers["pub_uid"] = userId
debugInfoSync("🔐 添加认证 header: pub_uid = \(userId)")
}
if let userTicket = await UserInfoManager.getCurrentUserTicket() {
headers["pub_ticket"] = userTicket
debugInfoSync("🔐 添加认证 header: pub_ticket = \(userTicket.prefix(20))...")
}
} else {
debugInfoSync("🔐 跳过认证 header 添加 - 认证状态: \(authStatus.description)")
}
return headers
}
}
// MARK: - Request Models
struct LoginRequest: Codable {
let username: String
let password: String
}
// MARK: - Empty Request
struct EmptyRequest: Codable {}