Utoljára aktív 1733398371

Kinda self explanatory

TheRealToxicDev's Avatar TheRealToxicDev gist felülvizsgálása 1733398371. Revízióhoz ugrás

1 file changed, 166 insertions

ptero.js(fájl létrehozva)

@@ -0,0 +1,166 @@
1 + import axios from 'axios'
2 +
3 + export class PterodactylClient {
4 + constructor(apiUrl, apiKey) {
5 + this.apiUrl = apiUrl
6 + this.apiKey = apiKey
7 + this.client = axios.create({
8 + baseURL: apiUrl,
9 + headers: {
10 + 'Authorization': `Bearer ${apiKey}`,
11 + 'Accept': 'application/json',
12 + 'Content-Type': 'application/json'
13 + }
14 + })
15 + }
16 +
17 + async getNodes() {
18 + try {
19 + const response = await this.client.get('/api/application/nodes')
20 + return response.data.data
21 + } catch (error) {
22 + console.error('Error fetching nodes:', error)
23 + throw error
24 + }
25 + }
26 +
27 + async getNodeById(nodeId) {
28 + try {
29 + const response = await this.client.get(`/api/application/nodes/${nodeId}`)
30 + return response.data.data
31 + } catch (error) {
32 + console.error(`Error fetching node with ID ${nodeId}:`, error)
33 + throw error
34 + }
35 + }
36 +
37 + async getUsers() {
38 + try {
39 + const response = await this.client.get('/api/application/users')
40 + return response.data.data
41 + } catch (error) {
42 + console.error('Error fetching users:', error)
43 + throw error
44 + }
45 + }
46 +
47 + async getUserById(userId) {
48 + try {
49 + const response = await this.client.get(`/api/application/users/${userId}`)
50 + return response.data.data
51 + } catch (error) {
52 + console.error(`Error fetching user with ID ${userId}:`, error)
53 + throw error
54 + }
55 + }
56 +
57 + async createUser(userData) {
58 + try {
59 + const response = await this.client.post('/api/application/users', userData)
60 + return response.data.data
61 + } catch (error) {
62 + console.error('Error creating user:', error)
63 + throw error
64 + }
65 + }
66 +
67 + async updateUser(userId, userData) {
68 + try {
69 + const response = await this.client.patch(`/api/application/users/${userId}`, userData)
70 + return response.data.data
71 + } catch (error) {
72 + console.error(`Error updating user with ID ${userId}:`, error)
73 + throw error
74 + }
75 + }
76 +
77 + async deleteUser(userId) {
78 + try {
79 + await this.client.delete(`/api/application/users/${userId}`)
80 + return { success: true }
81 + } catch (error) {
82 + console.error(`Error deleting user with ID ${userId}:`, error)
83 + throw error
84 + }
85 + }
86 +
87 + async getServers() {
88 + try {
89 + const response = await this.client.get('/api/application/servers')
90 + return response.data.data
91 + } catch (error) {
92 + console.error('Error fetching servers:', error)
93 + throw error
94 + }
95 + }
96 +
97 + async getServerById(serverId) {
98 + try {
99 + const response = await this.client.get(`/api/application/servers/${serverId}`)
100 + return response.data.data
101 + } catch (error) {
102 + console.error(`Error fetching server with ID ${serverId}:`, error)
103 + throw error
104 + }
105 + }
106 +
107 + async createServer(serverData) {
108 + try {
109 + const response = await this.client.post('/api/application/servers', serverData)
110 + return response.data.data
111 + } catch (error) {
112 + console.error('Error creating server:', error)
113 + throw error
114 + }
115 + }
116 +
117 + async updateServer(serverId, serverData) {
118 + try {
119 + const response = await this.client.patch(`/api/application/servers/${serverId}`, serverData)
120 + return response.data.data
121 + } catch (error) {
122 + console.error(`Error updating server with ID ${serverId}:`, error)
123 + throw error
124 + }
125 + }
126 +
127 + async deleteServer(serverId) {
128 + try {
129 + await this.client.delete(`/api/application/servers/${serverId}`)
130 + return { success: true }
131 + } catch (error) {
132 + console.error(`Error deleting server with ID ${serverId}:`, error)
133 + throw error
134 + }
135 + }
136 +
137 + async suspendServer(serverId) {
138 + try {
139 + const response = await this.client.post(`/api/application/servers/${serverId}/suspend`)
140 + return response.data.data
141 + } catch (error) {
142 + console.error(`Error suspending server with ID ${serverId}:`, error)
143 + throw error
144 + }
145 + }
146 +
147 + async unsuspendServer(serverId) {
148 + try {
149 + const response = await this.client.post(`/api/application/servers/${serverId}/unsuspend`)
150 + return response.data.data
151 + } catch (error) {
152 + console.error(`Error unsuspending server with ID ${serverId}:`, error)
153 + throw error
154 + }
155 + }
156 +
157 + async reinstallServer(serverId) {
158 + try {
159 + const response = await this.client.post(`/api/application/servers/${serverId}/reinstall`)
160 + return response.data.data
161 + } catch (error) {
162 + console.error(`Error reinstalling server with ID ${serverId}:`, error)
163 + throw error
164 + }
165 + }
166 + }
Újabb Régebbi