@woopsy/mcpanel 2.1.0 → 2.1.1

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.
@@ -80,7 +80,8 @@ class ConfigManager {
80
80
  */
81
81
  load() {
82
82
  if (!fs.existsSync(CONFIG_PATH)) {
83
- this.config = { ...DEFAULT_CONFIG };
83
+ this.config = { ...DEFAULT_CONFIG, playitSettings: {} };
84
+ this.migrateLegacyConfig();
84
85
  this.save();
85
86
  return;
86
87
  }
@@ -121,6 +122,9 @@ class ConfigManager {
121
122
  server,
122
123
  externalBackups: parsed.externalBackups || [],
123
124
  };
125
+ // Recover an already-claimed playit secret from the pre-2.0 config
126
+ // location before persisting (no-op once a secret is present here).
127
+ this.migrateLegacyConfig();
124
128
  // Persist the migrated shape so the legacy keys are cleaned up on disk.
125
129
  this.save();
126
130
  }
@@ -131,6 +135,42 @@ class ConfigManager {
131
135
  this.save();
132
136
  }
133
137
  }
138
+ /**
139
+ * Recovers settings written by versions <2.0, which stored config.json next
140
+ * to the app (`APP_ROOT/config.json`) instead of in `~/.mcpanel`. Without
141
+ * this, an already-claimed playit agent secret is invisible to the new
142
+ * location, so the agent gets re-claimed in the browser on every launch.
143
+ *
144
+ * Only runs when the current config has no playit secret, and never
145
+ * overwrites values already present in the new location.
146
+ */
147
+ migrateLegacyConfig() {
148
+ const legacyPath = path.join(exports.APP_ROOT, 'config.json');
149
+ if (legacyPath === CONFIG_PATH)
150
+ return; // same file — nothing to migrate
151
+ if (this.config.playitSettings.secret)
152
+ return; // already linked
153
+ if (!fs.existsSync(legacyPath))
154
+ return;
155
+ try {
156
+ const legacy = JSON.parse(fs.readFileSync(legacyPath, 'utf-8'));
157
+ if (legacy?.playitSettings?.secret) {
158
+ // Bring the secret + last-known tunnel forward so the existing agent
159
+ // and tunnel are reused instead of re-claimed/recreated.
160
+ this.config.playitSettings = {
161
+ ...legacy.playitSettings,
162
+ ...this.config.playitSettings,
163
+ };
164
+ }
165
+ // Adopt the legacy server only if none is synced in the new location.
166
+ if (!this.config.server && legacy.server && typeof legacy.server === 'object') {
167
+ this.config.server = legacy.server;
168
+ }
169
+ }
170
+ catch {
171
+ // Unreadable/corrupt legacy config — ignore and continue with defaults.
172
+ }
173
+ }
134
174
  /**
135
175
  * Saves the current config memory state to disk
136
176
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@woopsy/mcpanel",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "MCPANEL — a terminal-based, single-server Minecraft server manager with an Arch/neofetch-style UI, live logs, backups, plugins and Playit.gg tunnels.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {