拆分Models

This commit is contained in:
anlicheng 2026-04-17 15:18:08 +08:00
parent ec817b27b8
commit 943eee00b1
8 changed files with 200 additions and 166 deletions

View File

@ -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

View File

@ -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(),

View 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"
}
}

View 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"
}
}

View 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"
}
}
}

View 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"
}
}

View File

@ -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] = [

View File

@ -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] = [