feat: add remote reboot support

This commit is contained in:
2026-04-19 16:53:17 +02:00
parent 92040e5c5e
commit afbb425e3b
11 changed files with 381 additions and 19 deletions

View File

@@ -181,7 +181,7 @@ class APIv2_12: BaseAPIClient, ServerAPIProtocol {
}
guard httpResponse.statusCode == 200 else {
throw APIError.httpError(httpResponse.statusCode)
throw APIError.httpError(httpResponse.statusCode, nil)
}
let decoder = JSONDecoder()
@@ -189,6 +189,10 @@ class APIv2_12: BaseAPIClient, ServerAPIProtocol {
let envelope = try decoder.decode(ServerSummaryEnvelope.self, from: data)
return envelope.toDomain()
}
func restartServer(apiKey: String) async throws {
throw APIError.unsupportedFeature("Server reboot")
}
}
// MARK: - Server Summary Mapping

View File

@@ -181,7 +181,7 @@ class APIv2_13: BaseAPIClient, ServerAPIProtocol {
}
guard httpResponse.statusCode == 200 else {
throw APIError.httpError(httpResponse.statusCode)
throw APIError.httpError(httpResponse.statusCode, nil)
}
let decoder = JSONDecoder()
@@ -189,6 +189,10 @@ class APIv2_13: BaseAPIClient, ServerAPIProtocol {
let envelope = try decoder.decode(ServerSummaryEnvelope.self, from: data)
return envelope.toDomain()
}
func restartServer(apiKey: String) async throws {
throw APIError.unsupportedFeature("Server reboot")
}
}
// MARK: - Server Summary Mapping

View File

@@ -0,0 +1,30 @@
//
// APIv2_14.swift
// iKeyMon
//
// Created by tracer on 19.04.26.
//
import Foundation
class APIv2_14: APIv2_13 {
private enum Endpoint: String {
case serverReboot = "/api/v2/server/reboot"
func url(baseURL: URL) -> URL {
baseURL.appendingPathComponent(rawValue)
}
}
override func restartServer(apiKey: String) async throws {
var request = URLRequest(url: Endpoint.serverReboot.url(baseURL: baseURL))
request.httpMethod = "POST"
request.setValue(apiKey, forHTTPHeaderField: "X-API-KEY")
request.setValue("application/json", forHTTPHeaderField: "Accept")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.timeoutInterval = 30
request.httpBody = #"{"confirm":true}"#.data(using: .utf8)
try await performRequestWithoutBody(request)
}
}