@woopsy/mcpanel 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ConfigManager = exports.APP_ROOT = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ // Dynamically resolve application root folder
40
+ exports.APP_ROOT = fs.existsSync(path.join(__dirname, '..', '..', 'package.json'))
41
+ ? path.resolve(__dirname, '..', '..')
42
+ : path.resolve(__dirname, '..');
43
+ const CONFIG_PATH = path.join(exports.APP_ROOT, 'config.json');
44
+ const DEFAULT_CONFIG = {
45
+ defaultJavaPath: 'java',
46
+ defaultRam: '4G',
47
+ autoBackupSettings: {
48
+ enabled: false,
49
+ intervalHours: 24,
50
+ },
51
+ playitSettings: {},
52
+ server: null,
53
+ externalBackups: [],
54
+ };
55
+ class ConfigManager {
56
+ config;
57
+ constructor() {
58
+ this.config = { ...DEFAULT_CONFIG };
59
+ }
60
+ /**
61
+ * Initializes folders and configuration file
62
+ */
63
+ initialize() {
64
+ const requiredDirs = ['backups', 'downloads', 'logs', 'playit'];
65
+ for (const dir of requiredDirs) {
66
+ const dirPath = path.join(exports.APP_ROOT, dir);
67
+ if (!fs.existsSync(dirPath)) {
68
+ fs.mkdirSync(dirPath, { recursive: true });
69
+ }
70
+ }
71
+ this.load();
72
+ }
73
+ /**
74
+ * Loads config.json from disk, falling back to defaults if missing or corrupted
75
+ */
76
+ load() {
77
+ if (!fs.existsSync(CONFIG_PATH)) {
78
+ this.config = { ...DEFAULT_CONFIG };
79
+ this.save();
80
+ return;
81
+ }
82
+ try {
83
+ const fileContent = fs.readFileSync(CONFIG_PATH, 'utf-8');
84
+ const parsed = JSON.parse(fileContent);
85
+ // Resolve the single managed server. Migrate from the legacy multi-server
86
+ // `servers` map (this CLI used to manage many) by adopting the first entry.
87
+ let server = null;
88
+ if (parsed.server && typeof parsed.server === 'object') {
89
+ const s = parsed.server;
90
+ server = {
91
+ name: s.name,
92
+ path: s.path,
93
+ version: s.version || 'Unknown',
94
+ software: s.software || 'Vanilla',
95
+ ram: s.ram || parsed.defaultRam || '4G',
96
+ };
97
+ }
98
+ else if (parsed.servers && typeof parsed.servers === 'object') {
99
+ const first = Object.values(parsed.servers)[0];
100
+ if (first) {
101
+ server = {
102
+ name: first.name,
103
+ path: first.path,
104
+ version: first.version || 'Unknown',
105
+ software: first.software || 'Vanilla',
106
+ ram: first.ram || parsed.defaultRam || '4G',
107
+ };
108
+ }
109
+ }
110
+ // Ensure key sections are initialized
111
+ this.config = {
112
+ defaultJavaPath: parsed.defaultJavaPath || 'java',
113
+ defaultRam: parsed.defaultRam || '4G',
114
+ autoBackupSettings: parsed.autoBackupSettings || { enabled: false, intervalHours: 24 },
115
+ playitSettings: parsed.playitSettings || {},
116
+ server,
117
+ externalBackups: parsed.externalBackups || [],
118
+ };
119
+ // Persist the migrated shape so the legacy keys are cleaned up on disk.
120
+ this.save();
121
+ }
122
+ catch (error) {
123
+ // Config corrupted
124
+ console.warn('⚠️ Config file is corrupted. Rebuilding default config.json...');
125
+ this.config = { ...DEFAULT_CONFIG };
126
+ this.save();
127
+ }
128
+ }
129
+ /**
130
+ * Saves the current config memory state to disk
131
+ */
132
+ save() {
133
+ try {
134
+ fs.writeFileSync(CONFIG_PATH, JSON.stringify(this.config, null, 2), 'utf-8');
135
+ }
136
+ catch (error) {
137
+ console.error('❌ Failed to save configuration file:', error);
138
+ }
139
+ }
140
+ /**
141
+ * Retrieves the raw config reference
142
+ */
143
+ getConfig() {
144
+ return this.config;
145
+ }
146
+ /**
147
+ * Updates general settings
148
+ */
149
+ updateSettings(updates) {
150
+ this.config = { ...this.config, ...updates };
151
+ this.save();
152
+ }
153
+ /**
154
+ * Sets (or replaces) the single managed Minecraft server.
155
+ */
156
+ setServer(server) {
157
+ this.config.server = server;
158
+ this.save();
159
+ }
160
+ /**
161
+ * Returns the single managed server, or null if none is synced yet.
162
+ */
163
+ getServer() {
164
+ return this.config.server;
165
+ }
166
+ /**
167
+ * Persists the playit agent secret key so the tunnel only needs claiming once.
168
+ */
169
+ setPlayitSecret(secret) {
170
+ this.config.playitSettings.secret = secret;
171
+ this.save();
172
+ }
173
+ /**
174
+ * Persists the last known tunnel details for status reporting between sessions.
175
+ */
176
+ updatePlayitTunnel(details) {
177
+ this.config.playitSettings = { ...this.config.playitSettings, ...details };
178
+ this.save();
179
+ }
180
+ /**
181
+ * Adds an external backup location
182
+ */
183
+ addExternalBackup(backupPath) {
184
+ const absolute = path.resolve(backupPath);
185
+ if (!this.config.externalBackups.includes(absolute)) {
186
+ this.config.externalBackups.push(absolute);
187
+ this.save();
188
+ return true;
189
+ }
190
+ return false;
191
+ }
192
+ }
193
+ exports.ConfigManager = ConfigManager;