91 lines
2.9 KiB
Swift
91 lines
2.9 KiB
Swift
//
|
|
// SDLAPIClient+App.swift
|
|
// punchnet
|
|
//
|
|
// Created by 安礼成 on 2026/3/21.
|
|
//
|
|
import Foundation
|
|
|
|
extension SDLAPIClient {
|
|
|
|
struct AppPoliciesInfo: Codable {
|
|
let privacyPolicyUrl: String
|
|
let termsOfServiceUrl: String
|
|
let privacyPolicyVersion: String
|
|
let termsVersion: String
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case privacyPolicyUrl = "privacy_policy_url"
|
|
case termsOfServiceUrl = "terms_of_service_url"
|
|
case privacyPolicyVersion = "privacy_policy_version"
|
|
case termsVersion = "terms_version"
|
|
}
|
|
}
|
|
|
|
// 应用升级信息
|
|
struct AppUpgradeInfo: Codable, Identifiable {
|
|
var id = UUID().uuidString
|
|
|
|
let hasUpdate: Bool
|
|
let latestVersion: String
|
|
let latestBuild: Int
|
|
// 强制升级的url地址
|
|
let forceUpdateUrl: String?
|
|
let releaseNotes: String
|
|
let minSupportedVersion: String
|
|
let publishTime: Int
|
|
|
|
// 是否强制升级
|
|
var forceUpdate: Bool {
|
|
return forceUpdateUrl != nil
|
|
}
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case hasUpdate = "has_update"
|
|
case latestVersion = "latest_version"
|
|
case latestBuild = "latest_build"
|
|
case forceUpdateUrl = "force_update"
|
|
case releaseNotes = "release_notes"
|
|
case minSupportedVersion = "min_supported_version"
|
|
case publishTime = "publish_time"
|
|
}
|
|
}
|
|
|
|
// 提交用户反馈
|
|
static func appIssue(accessToken: String, contact: String, content: String) async throws -> String {
|
|
let params: [String: Any] = [
|
|
"access_token": accessToken,
|
|
"contact": contact,
|
|
"platform": SystemConfig.systemInfo,
|
|
"content": content,
|
|
"client_id": SystemConfig.getClientId(),
|
|
"mac": SystemConfig.macAddressString(mac: SystemConfig.getMacAddress())
|
|
]
|
|
|
|
return try await SDLAPIClient.doPost(path: "/app/issue", params: params, as: String.self)
|
|
}
|
|
|
|
// 隐私和服务政策
|
|
static func appPolicies() async throws -> AppPoliciesInfo {
|
|
let params: [String: Any] = [
|
|
"platform": "macos",
|
|
"client_id": SystemConfig.getClientId()
|
|
]
|
|
return try await SDLAPIClient.doPost(path: "/app/policies", params: params, as: AppPoliciesInfo.self)
|
|
}
|
|
|
|
// 检查app升级
|
|
static func appCheckUpdate() async throws -> AppUpgradeInfo {
|
|
let params: [String: Any] = [
|
|
"app_id": "Punchnet",
|
|
"platform": "macos",
|
|
"version": SystemConfig.systemInfo,
|
|
"build": SystemConfig.build,
|
|
"channel": SystemConfig.channel,
|
|
"client_id": SystemConfig.getClientId()
|
|
]
|
|
return try await SDLAPIClient.doPost(path: "/app/checkUpdate", params: params, as: AppUpgradeInfo.self)
|
|
}
|
|
|
|
}
|