@lethevimlet/sshift 1.9.5 → 1.9.6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lethevimlet/sshift",
3
- "version": "1.9.5",
3
+ "version": "1.9.6",
4
4
  "description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
5
5
  "main": "src/server/index.js",
6
6
  "bin": {
@@ -26,6 +26,7 @@
26
26
  * GET /v1/screen?sessionId=&history=N
27
27
  * POST /v1/switch { sessionId }
28
28
  * POST /v1/rename { sessionId, name } → renames the tab on every browser
29
+ * POST /v1/close { sessionId } → closes the tab (ends its SSH session) everywhere
29
30
  * POST /v1/open { bookmarkId } → opens it on ONE connected browser
30
31
  * POST /v1/type { sessionId?, text }
31
32
  * POST /v1/key { sessionId?, key, repeat? }
@@ -162,6 +163,7 @@ class RemoteControlPlugin {
162
163
  case 'GET /v1/screen': return send(200, this.screen(url.searchParams.get('sessionId'), url.searchParams.get('history')));
163
164
  case 'POST /v1/switch': return send(200, this.switchTab(body.sessionId));
164
165
  case 'POST /v1/rename': return send(200, this.renameTab(body.sessionId, body.name));
166
+ case 'POST /v1/close': return send(200, this.closeTab(body.sessionId));
165
167
  case 'POST /v1/open': return send(200, await this.open(body.bookmarkId));
166
168
  case 'POST /v1/type': return send(200, await this.type(body.sessionId, body.text));
167
169
  case 'POST /v1/key': return send(200, await this.key(body.sessionId, body.key, body.repeat));
@@ -236,6 +238,14 @@ class RemoteControlPlugin {
236
238
  return { switched: true, sessionId, name: tab?.name || null };
237
239
  }
238
240
 
241
+ closeTab(sessionId) {
242
+ if (typeof sessionId !== 'string' || !sessionId) throw new HttpError(400, 'sessionId required');
243
+ const tab = this.ctx.getTabs().tabs.find(t => t.sessionId === sessionId);
244
+ if (!tab) throw new HttpError(404, 'Tab not found');
245
+ if (typeof this.ctx.closeTab !== 'function' || !this.ctx.closeTab(sessionId)) throw new HttpError(404, 'Tab not found');
246
+ return { closed: true, sessionId, name: tab.name, position: tab.position };
247
+ }
248
+
239
249
  renameTab(sessionId, name) {
240
250
  if (typeof sessionId !== 'string' || !sessionId) throw new HttpError(400, 'sessionId required');
241
251
  const clean = typeof name === 'string' ? name.trim().replace(/\s+/g, ' ') : '';
@@ -27,6 +27,7 @@
27
27
  * - ctx.getTabs() - Open tabs in order, with the focused session
28
28
  * - ctx.switchTab(sessionId) - Focus a tab on every connected client
29
29
  * - ctx.renameTab(sessionId, name) - Rename a tab on the server and every client
30
+ * - ctx.closeTab(sessionId) - Close a tab (ends its session) everywhere
30
31
  * - ctx.getBookmarks() - Bookmark names/types (never credentials)
31
32
  * - ctx.requestClientAction(event, data, opts) - Ask exactly ONE connected client to act
32
33
  * - ctx.getDataDir() - User data directory (private plugin state)
@@ -301,6 +302,21 @@ class PluginManager {
301
302
  return true;
302
303
  },
303
304
 
305
+ closeTab(sessionId) {
306
+ // Same as a user closing the tab: end the SSH/SFTP session and remove it everywhere.
307
+ const tm = self.tabManager;
308
+ const tab = tm && tm.getTab(sessionId);
309
+ if (!tab) return false;
310
+ tm.clearCloseTimer(sessionId);
311
+ tm.removeTab(sessionId);
312
+ if (tab.type === 'ssh' && self.sshManager) self.sshManager.disconnect(sessionId);
313
+ if (tab.type === 'sftp') {
314
+ try { require('../services').sftpManager.disconnect(sessionId); } catch (e) { /* ignore */ }
315
+ }
316
+ if (self.io) { self.io.emit('tab-closed', { sessionId }); self.io.emit('sessions-updated'); }
317
+ return true;
318
+ },
319
+
304
320
  renameTab(sessionId, name) {
305
321
  const tm = self.tabManager;
306
322
  if (!tm || !tm.getTab(sessionId)) return false;