|
| 1 | +import type { $Fetch } from 'ofetch'; |
| 2 | +import type { ApiResponse } from '..'; |
| 3 | + |
| 4 | +export class DedicatedServerApiService { |
| 5 | + public constructor(private apiFetch: $Fetch) {} |
| 6 | + |
| 7 | + /** |
| 8 | + * Perform an action on a dedicated server |
| 9 | + * @param id Service ID |
| 10 | + * @param action Action to perform |
| 11 | + */ |
| 12 | + public performAction(id: string, action: DedicatedServerAction) { |
| 13 | + return this.apiFetch<ApiResponse<void>>(`/services/${id}/dedicated/action`, { |
| 14 | + method: 'POST', |
| 15 | + body: { action }, |
| 16 | + }); |
| 17 | + } |
| 18 | + |
| 19 | + /** |
| 20 | + * Get hardware components of a dedicated server |
| 21 | + * @param id Service ID |
| 22 | + */ |
| 23 | + public getHardwareComponents(id: string) { |
| 24 | + return this.apiFetch<ApiResponse<DedicatedServerHardwareComponent>>( |
| 25 | + `/services/${id}/dedicated/hardware`, |
| 26 | + ); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Get dedicated server details |
| 31 | + * @param id Service ID |
| 32 | + */ |
| 33 | + public getDetails(id: string) { |
| 34 | + return this.apiFetch<ApiResponse<DedicatedServerDetails>>(`/services/${id}/dedicated/info`); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Get available OS templates for a dedicated server |
| 39 | + * @param id Service ID |
| 40 | + */ |
| 41 | + public getOsTemplates(id: string) { |
| 42 | + return this.apiFetch<ApiResponse<DedicatedServerOsTemplate[]>>( |
| 43 | + `/services/${id}/dedicated/os-templates`, |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + public getReinstallStatus(id: string) { |
| 48 | + return this.apiFetch<ApiResponse<DedicatedServerReinstallStatus>>( |
| 49 | + `/services/${id}/dedicated/reinstall-status`, |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Reinstall a dedicated server with a new OS |
| 55 | + * @param id Service ID |
| 56 | + */ |
| 57 | + public reinstall(id: string, data: DedicatedServerReinstallData) { |
| 58 | + return this.apiFetch<ApiResponse<void>>(`/services/${id}/dedicated/reinstall`, { |
| 59 | + method: 'POST', |
| 60 | + body: data, |
| 61 | + }); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Get dedicated server tasks |
| 66 | + * @param id Service ID |
| 67 | + */ |
| 68 | + public getTasks(id: string) { |
| 69 | + return this.apiFetch<ApiResponse<DedicatedServerTask[]>>(`/services/${id}/dedicated/tasks`); |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +/** |
| 74 | + * Represents the action to be performed on a dedicated server. |
| 75 | + */ |
| 76 | +export enum DedicatedServerAction { |
| 77 | + Start = 'setPowerOn', |
| 78 | + Stop = 'setPowerOff', |
| 79 | + Restart = 'setPowerReset', |
| 80 | +} |
| 81 | + |
| 82 | +/** |
| 83 | + * Represents CPU details and usage for a dedicated server. |
| 84 | + */ |
| 85 | +export interface DedicatedServerCpuDetails { |
| 86 | + /** |
| 87 | + * Model of the CPU. |
| 88 | + * @example "AMD Ryzen 9 5950X" |
| 89 | + */ |
| 90 | + model: string; |
| 91 | + |
| 92 | + /** |
| 93 | + * Base speed of the CPU in MHz. |
| 94 | + * @example 3500 |
| 95 | + */ |
| 96 | + speed: number; |
| 97 | + |
| 98 | + /** |
| 99 | + * Turbo speed of the CPU in MHz. |
| 100 | + * @example 4900 |
| 101 | + */ |
| 102 | + turboSpeed: number; |
| 103 | + |
| 104 | + /** |
| 105 | + * Number of CPU cores. |
| 106 | + * @example 16 |
| 107 | + */ |
| 108 | + cores: number; |
| 109 | + |
| 110 | + /** |
| 111 | + * Number of CPU threads. |
| 112 | + * @example 32 |
| 113 | + */ |
| 114 | + threads: number; |
| 115 | +} |
| 116 | + |
| 117 | +/** |
| 118 | + * Represents the detailed information about a dedicated server. |
| 119 | + */ |
| 120 | +export interface DedicatedServerDetails { |
| 121 | + /** |
| 122 | + * Unique identifier for the dedicated server. |
| 123 | + * @example "1" |
| 124 | + */ |
| 125 | + dedicatedId: string; |
| 126 | + |
| 127 | + /** |
| 128 | + * Current status of the dedicated server. |
| 129 | + * @example true |
| 130 | + */ |
| 131 | + status: boolean; |
| 132 | + |
| 133 | + /** |
| 134 | + * List of available actions for the dedicated server. |
| 135 | + */ |
| 136 | + availableActions: DedicatedServerAction[]; |
| 137 | + |
| 138 | + /** |
| 139 | + * Model of the mainboard. |
| 140 | + * @example "ASUS ROG Strix X570-E Gaming" |
| 141 | + */ |
| 142 | + mainboard: string; |
| 143 | + |
| 144 | + /** |
| 145 | + * Amount of RAM in GB. |
| 146 | + * @example 128 |
| 147 | + */ |
| 148 | + ram: number; |
| 149 | + |
| 150 | + /** |
| 151 | + * Total disk space in GB. |
| 152 | + * @example 1000 |
| 153 | + */ |
| 154 | + disk: number; |
| 155 | + |
| 156 | + /** |
| 157 | + * CPU details for the dedicated server. |
| 158 | + */ |
| 159 | + cpu: DedicatedServerCpuDetails; |
| 160 | +} |
| 161 | + |
| 162 | +/** |
| 163 | + * Represents an operating system template available for a dedicated server. |
| 164 | + */ |
| 165 | +export interface DedicatedServerOsTemplate { |
| 166 | + /** |
| 167 | + * OS version ID. |
| 168 | + * @example 1 |
| 169 | + */ |
| 170 | + id: number; |
| 171 | + |
| 172 | + /** |
| 173 | + * OS version name. |
| 174 | + * @example "Debian 9.5" |
| 175 | + */ |
| 176 | + name: string; |
| 177 | +} |
| 178 | + |
| 179 | +/** |
| 180 | + * Represents the data required to reinstall a dedicated server with a new OS. |
| 181 | + */ |
| 182 | +export interface DedicatedServerReinstallData { |
| 183 | + /** |
| 184 | + * New root password for the dedicated server |
| 185 | + * @example "StrongPassword123!" |
| 186 | + */ |
| 187 | + password: string; |
| 188 | + |
| 189 | + /** |
| 190 | + * ID of the new OS to install |
| 191 | + * @example 1 |
| 192 | + */ |
| 193 | + osId: number; |
| 194 | +} |
| 195 | + |
| 196 | +/** |
| 197 | + * Represents a task related to a dedicated server, such as rebooting or restoring a backup. |
| 198 | + */ |
| 199 | +export interface DedicatedServerTask { |
| 200 | + /** |
| 201 | + * Description of the task action. |
| 202 | + * @example "Server reboot initiated" |
| 203 | + */ |
| 204 | + action: string; |
| 205 | + |
| 206 | + /** |
| 207 | + * Unix timestamp when the task started. |
| 208 | + * @example 1625251200000 |
| 209 | + */ |
| 210 | + startedAt: number; |
| 211 | + |
| 212 | + /** |
| 213 | + * Unix timestamp when the task was last updated. |
| 214 | + * @example 1625254800000 |
| 215 | + */ |
| 216 | + updatedAt: number; |
| 217 | +} |
| 218 | + |
| 219 | +/** |
| 220 | + * Represents a hardware component of a dedicated server, including its model and specifications. |
| 221 | + */ |
| 222 | +export interface DedicatedServerHardwareComponent { |
| 223 | + /** |
| 224 | + * Hardware component name. |
| 225 | + * @example "CPU Model" |
| 226 | + */ |
| 227 | + component: string; |
| 228 | + |
| 229 | + /** |
| 230 | + * Model of the hardware component. |
| 231 | + * @example "AMD Ryzen 9 9950X" |
| 232 | + */ |
| 233 | + model: string; |
| 234 | + |
| 235 | + /** |
| 236 | + * Value of the hardware component. |
| 237 | + * @example 5000 |
| 238 | + */ |
| 239 | + value: number; |
| 240 | + |
| 241 | + /** |
| 242 | + * Unit of the value. |
| 243 | + * @example " MHz" |
| 244 | + */ |
| 245 | + valueSuffix: string; |
| 246 | +} |
| 247 | + |
| 248 | +/** |
| 249 | + * Enum representing the steps of the reinstall process for a dedicated server. |
| 250 | + */ |
| 251 | +export enum DedicatedServerReinstallStep { |
| 252 | + RebootingServer = 0, |
| 253 | + PreparingBootEnvironment = 1, |
| 254 | + InstallingOperatingSystem = 2, |
| 255 | + InstallationCompleted = 3, |
| 256 | +} |
| 257 | + |
| 258 | +/** |
| 259 | + * Represents the status of the reinstall process for a dedicated server. |
| 260 | + */ |
| 261 | +export interface DedicatedServerReinstallStatus { |
| 262 | + /** |
| 263 | + * Whether the reinstall process is completed. |
| 264 | + * @example true |
| 265 | + */ |
| 266 | + completed: boolean; |
| 267 | + |
| 268 | + /** |
| 269 | + * Current step of the reinstall process. |
| 270 | + * @example 1 |
| 271 | + * @enum {0, 1, 2, 3} |
| 272 | + */ |
| 273 | + step: DedicatedServerReinstallStep; |
| 274 | +} |
0 commit comments