拆分Models
This commit is contained in:
parent
ec817b27b8
commit
943eee00b1
@ -17,7 +17,7 @@ class AppContext {
|
||||
private var vpnManager = VPNManager.shared
|
||||
|
||||
// 调用 "/connect" 之后的网络信息
|
||||
var networkContext: SDLAPIClient.NetworkContext? = nil
|
||||
var networkContext: NetworkContext? = nil
|
||||
|
||||
// 当前选择的出口节点 IP,为 nil 表示不设置出口节点
|
||||
var selectedExitNodeIp: String? = nil
|
||||
|
||||
@ -8,107 +8,6 @@ import Foundation
|
||||
|
||||
extension SDLAPIClient {
|
||||
|
||||
// 用来做临时的数据解析
|
||||
struct NetworkContext: Codable {
|
||||
let ip: String
|
||||
let maskLen: UInt8
|
||||
// 主机名称
|
||||
let hostname: String
|
||||
let identityId: UInt32
|
||||
let resourceList: [Resource]
|
||||
let nodeList: [Node]
|
||||
let exitNodeList: [ExitNode]
|
||||
|
||||
struct ExitNode: Codable {
|
||||
let uuid = UUID().uuidString
|
||||
let nnid: Int
|
||||
let nodeName: String
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case nnid = "node_id"
|
||||
case nodeName = "node_name"
|
||||
}
|
||||
}
|
||||
|
||||
// 资源列表
|
||||
struct Resource: Codable {
|
||||
var uuid = UUID().uuidString
|
||||
var id: Int
|
||||
var name: String
|
||||
var url: String
|
||||
var connectionStatus: String
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id
|
||||
case name
|
||||
case url
|
||||
case connectionStatus = "connection_status"
|
||||
}
|
||||
}
|
||||
|
||||
// 设备列表
|
||||
struct Node: Codable {
|
||||
var id: Int
|
||||
var name: String
|
||||
var ip: String
|
||||
var system: String?
|
||||
var connectionStatus: String
|
||||
|
||||
func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(id)
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id
|
||||
case name
|
||||
case ip
|
||||
case system
|
||||
case connectionStatus = "connection_status"
|
||||
}
|
||||
|
||||
static func == (lhs: Self, rhs: Self) -> Bool {
|
||||
return lhs.id == rhs.id
|
||||
}
|
||||
}
|
||||
|
||||
// 节点详情
|
||||
struct NodeDetail: Codable {
|
||||
let id: Int
|
||||
let name: String
|
||||
let ip: String
|
||||
let system: String?
|
||||
let connectionStatus: String
|
||||
let resourceList: [Resource]
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id
|
||||
case name
|
||||
case ip
|
||||
case system
|
||||
case connectionStatus = "connection_status"
|
||||
case resourceList = "resource_list"
|
||||
}
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case ip
|
||||
case maskLen = "mask_len"
|
||||
case hostname
|
||||
case identityId = "identity_id"
|
||||
case resourceList = "resource_list"
|
||||
case nodeList = "node_list"
|
||||
case exitNodeList = "exit_node"
|
||||
}
|
||||
|
||||
func getNode(id: Int?) -> Node? {
|
||||
return nodeList.first(where: { $0.id == id })
|
||||
}
|
||||
|
||||
func firstNodeId() -> Int? {
|
||||
return nodeList.first?.id
|
||||
}
|
||||
}
|
||||
|
||||
static func connectNetwork(accesToken: String) async throws -> NetworkContext {
|
||||
let params: [String: Any] = [
|
||||
"client_id": SystemConfig.getClientId(),
|
||||
|
||||
21
punchnet/Shared/Models/AppPoliciesInfo.swift
Normal file
21
punchnet/Shared/Models/AppPoliciesInfo.swift
Normal file
@ -0,0 +1,21 @@
|
||||
//
|
||||
// AppPoliciesInfo.swift
|
||||
// punchnet
|
||||
//
|
||||
// Created by 安礼成 on 2026/4/17.
|
||||
//
|
||||
import Foundation
|
||||
|
||||
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"
|
||||
}
|
||||
}
|
||||
32
punchnet/Shared/Models/AppUpgradeInfo.swift
Normal file
32
punchnet/Shared/Models/AppUpgradeInfo.swift
Normal file
@ -0,0 +1,32 @@
|
||||
//
|
||||
// AppUpgradeInfo.swift
|
||||
// punchnet
|
||||
//
|
||||
// Created by 安礼成 on 2026/4/17.
|
||||
//
|
||||
import Foundation
|
||||
|
||||
// 应用升级信息
|
||||
struct AppUpgradeInfo: Codable, Identifiable {
|
||||
var id = UUID().uuidString
|
||||
|
||||
let hasUpdate: Bool
|
||||
let latestVersion: String
|
||||
let latestBuild: Int
|
||||
let forceUpdate: Bool
|
||||
let downloadUrl: String
|
||||
let releaseNotes: String
|
||||
let minSupportedVersion: String
|
||||
let publishTime: Int
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case hasUpdate = "has_update"
|
||||
case latestVersion = "latest_version"
|
||||
case latestBuild = "latest_build"
|
||||
case forceUpdate = "force_update"
|
||||
case downloadUrl = "download_url"
|
||||
case releaseNotes = "release_notes"
|
||||
case minSupportedVersion = "min_supported_version"
|
||||
case publishTime = "publish_time"
|
||||
}
|
||||
}
|
||||
111
punchnet/Shared/Models/NetworkContext.swift
Normal file
111
punchnet/Shared/Models/NetworkContext.swift
Normal file
@ -0,0 +1,111 @@
|
||||
//
|
||||
// NetworkContext.swift
|
||||
// punchnet
|
||||
//
|
||||
// Created by 安礼成 on 2026/4/17.
|
||||
//
|
||||
import Foundation
|
||||
|
||||
// 用来做临时的数据解析
|
||||
struct NetworkContext: Codable {
|
||||
let ip: String
|
||||
let maskLen: UInt8
|
||||
// 主机名称
|
||||
let hostname: String
|
||||
let identityId: UInt32
|
||||
let resourceList: [Resource]
|
||||
let nodeList: [Node]
|
||||
let exitNodeList: [ExitNode]
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case ip
|
||||
case maskLen = "mask_len"
|
||||
case hostname
|
||||
case identityId = "identity_id"
|
||||
case resourceList = "resource_list"
|
||||
case nodeList = "node_list"
|
||||
case exitNodeList = "exit_node"
|
||||
}
|
||||
|
||||
func getNode(id: Int?) -> Node? {
|
||||
return nodeList.first(where: { $0.id == id })
|
||||
}
|
||||
|
||||
func firstNodeId() -> Int? {
|
||||
return nodeList.first?.id
|
||||
}
|
||||
}
|
||||
|
||||
extension NetworkContext {
|
||||
|
||||
struct ExitNode: Codable {
|
||||
let uuid = UUID().uuidString
|
||||
let nnid: Int
|
||||
let nodeName: String
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case nnid = "node_id"
|
||||
case nodeName = "node_name"
|
||||
}
|
||||
}
|
||||
|
||||
// 资源列表
|
||||
struct Resource: Codable {
|
||||
var uuid = UUID().uuidString
|
||||
var id: Int
|
||||
var name: String
|
||||
var url: String
|
||||
var connectionStatus: String
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id
|
||||
case name
|
||||
case url
|
||||
case connectionStatus = "connection_status"
|
||||
}
|
||||
}
|
||||
|
||||
// 设备列表
|
||||
struct Node: Codable {
|
||||
var id: Int
|
||||
var name: String
|
||||
var ip: String
|
||||
var system: String?
|
||||
var connectionStatus: String
|
||||
|
||||
func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(id)
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id
|
||||
case name
|
||||
case ip
|
||||
case system
|
||||
case connectionStatus = "connection_status"
|
||||
}
|
||||
|
||||
static func == (lhs: Self, rhs: Self) -> Bool {
|
||||
return lhs.id == rhs.id
|
||||
}
|
||||
}
|
||||
|
||||
// 节点详情
|
||||
struct NodeDetail: Codable {
|
||||
let id: Int
|
||||
let name: String
|
||||
let ip: String
|
||||
let system: String?
|
||||
let connectionStatus: String
|
||||
let resourceList: [Resource]
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id
|
||||
case name
|
||||
case ip
|
||||
case system
|
||||
case connectionStatus = "connection_status"
|
||||
case resourceList = "resource_list"
|
||||
}
|
||||
}
|
||||
}
|
||||
34
punchnet/Shared/Models/NetworkSession.swift
Normal file
34
punchnet/Shared/Models/NetworkSession.swift
Normal file
@ -0,0 +1,34 @@
|
||||
//
|
||||
// NetworkSession.swift
|
||||
// punchnet
|
||||
//
|
||||
// Created by 安礼成 on 2026/4/17.
|
||||
//
|
||||
import Foundation
|
||||
|
||||
// 登陆后的网络会话信息
|
||||
struct NetworkSession: Codable {
|
||||
let accessToken: String
|
||||
let username: String
|
||||
let userType: String
|
||||
let audit: Int
|
||||
let networkId: Int
|
||||
let networkName: String
|
||||
let networkDomain: String
|
||||
|
||||
// TODO
|
||||
var networkUrl: String {
|
||||
return "https://www.test.cn/id=\(self.networkId)"
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case accessToken = "access_token"
|
||||
case username
|
||||
case userType = "user_type"
|
||||
case audit
|
||||
case networkId = "network_id"
|
||||
case networkName = "network_name"
|
||||
case networkDomain = "network_domain"
|
||||
}
|
||||
|
||||
}
|
||||
@ -8,45 +8,6 @@ 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
|
||||
let forceUpdate: Bool
|
||||
let downloadUrl: String
|
||||
let releaseNotes: String
|
||||
let minSupportedVersion: String
|
||||
let publishTime: Int
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case hasUpdate = "has_update"
|
||||
case latestVersion = "latest_version"
|
||||
case latestBuild = "latest_build"
|
||||
case forceUpdate = "force_update"
|
||||
case downloadUrl = "download_url"
|
||||
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] = [
|
||||
|
||||
@ -8,31 +8,7 @@ import Foundation
|
||||
|
||||
extension SDLAPIClient {
|
||||
|
||||
// 登陆后的网络会话信息
|
||||
struct NetworkSession: Codable {
|
||||
let accessToken: String
|
||||
let username: String
|
||||
let userType: String
|
||||
let audit: Int
|
||||
let networkId: Int
|
||||
let networkName: String
|
||||
let networkDomain: String
|
||||
|
||||
// TODO
|
||||
var networkUrl: String {
|
||||
return "https://www.test.cn/id=\(self.networkId)"
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case accessToken = "access_token"
|
||||
case username
|
||||
case userType = "user_type"
|
||||
case audit
|
||||
case networkId = "network_id"
|
||||
case networkName = "network_name"
|
||||
case networkDomain = "network_domain"
|
||||
}
|
||||
}
|
||||
|
||||
static func loginWithAccountAndPassword(username: String, password: String) async throws -> NetworkSession {
|
||||
var params: [String: Any] = [
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user