diff --git a/punchnet/App/AppContext.swift b/punchnet/App/AppContext.swift index b863add..4cbfacc 100644 --- a/punchnet/App/AppContext.swift +++ b/punchnet/App/AppContext.swift @@ -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 diff --git a/punchnet/Features/Network/API/SDLAPIClient+Network.swift b/punchnet/Features/Network/API/SDLAPIClient+Network.swift index 291142b..45391f5 100644 --- a/punchnet/Features/Network/API/SDLAPIClient+Network.swift +++ b/punchnet/Features/Network/API/SDLAPIClient+Network.swift @@ -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(), diff --git a/punchnet/Shared/Models/AppPoliciesInfo.swift b/punchnet/Shared/Models/AppPoliciesInfo.swift new file mode 100644 index 0000000..ac2f156 --- /dev/null +++ b/punchnet/Shared/Models/AppPoliciesInfo.swift @@ -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" + } +} diff --git a/punchnet/Shared/Models/AppUpgradeInfo.swift b/punchnet/Shared/Models/AppUpgradeInfo.swift new file mode 100644 index 0000000..f5e49a5 --- /dev/null +++ b/punchnet/Shared/Models/AppUpgradeInfo.swift @@ -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" + } +} diff --git a/punchnet/Shared/Models/NetworkContext.swift b/punchnet/Shared/Models/NetworkContext.swift new file mode 100644 index 0000000..542ce8d --- /dev/null +++ b/punchnet/Shared/Models/NetworkContext.swift @@ -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" + } + } +} diff --git a/punchnet/Shared/Models/NetworkSession.swift b/punchnet/Shared/Models/NetworkSession.swift new file mode 100644 index 0000000..5c0c802 --- /dev/null +++ b/punchnet/Shared/Models/NetworkSession.swift @@ -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" + } + +} diff --git a/punchnet/Shared/Networking/SDLAPIClient+App.swift b/punchnet/Shared/Networking/SDLAPIClient+App.swift index a0ec1d6..600d1a4 100644 --- a/punchnet/Shared/Networking/SDLAPIClient+App.swift +++ b/punchnet/Shared/Networking/SDLAPIClient+App.swift @@ -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] = [ diff --git a/punchnet/Shared/Networking/SDLAPIClient+User.swift b/punchnet/Shared/Networking/SDLAPIClient+User.swift index 7cd7b46..d2503f3 100644 --- a/punchnet/Shared/Networking/SDLAPIClient+User.swift +++ b/punchnet/Shared/Networking/SDLAPIClient+User.swift @@ -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] = [