Initial commit: Crafty Mod Installer

This commit is contained in:
noothenoot
2026-04-18 18:53:07 +03:00
parent d7250f326f
commit f3d8e45189
9 changed files with 1423 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
const axios = require('axios');
class CraftyClient {
constructor(baseUrl, token) {
this.baseUrl = baseUrl.replace(/\/$/, '');
this.token = token;
this.client = axios.create({
baseURL: `${this.baseUrl}/api/v2`,
headers: {
'Authorization': `Bearer ${this.token}`,
'Content-Type': 'application/json'
}
});
}
async testConnection() {
try {
const resp = await this.client.get('/stats');
return resp.status === 200;
} catch (err) {
console.error('Crafty Connection Error:', err.message);
return false;
}
}
async listServers() {
const resp = await this.client.get('/servers');
return resp.data.data;
}
async getServerDetails(serverId) {
const resp = await this.client.get(`/servers/${serverId}`);
return resp.data.data;
}
async createServer(name, type = 'minecraft_java', memory = 2048, port = 25565) {
const payload = {
server_name: name,
server_type: type,
mem_limit: memory,
server_port: port,
autostart: false
};
const resp = await this.client.post('/servers', payload);
return resp.data.data;
}
}
module.exports = CraftyClient;