@lethevimlet/sshift 1.1.3 → 1.1.5

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/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  # SSHIFT - Web-based SSH/SFTP Terminal Client for the AI Stack
4
4
 
5
+ [![Website](https://img.shields.io/badge/website-getsshift.dev-blue.svg)](https://getsshift.dev)
5
6
  [![Documentation](https://img.shields.io/badge/docs-GitHub%20Pages-blue.svg)](https://lethevimlet.github.io/sshift/)
6
7
  [![npm version](https://img.shields.io/npm/v/@lethevimlet/sshift.svg)](https://www.npmjs.com/package/@lethevimlet/sshift)
7
8
  [![Docker](https://img.shields.io/badge/Docker-ghcr.io/lethevimlet/sshift-blue.svg)](https://github.com/lethevimlet/sshift/pkgs/container/sshift)
@@ -40,9 +41,8 @@ A modern, responsive web-based SSH and SFTP terminal client built with Node.js,
40
41
  curl -fsSL https://raw.githubusercontent.com/lethevimlet/sshift/main/sshift-install.sh | bash
41
42
  ```
42
43
 
43
- **Windows (PowerShell):**
44
+ **Windows PowerShell (Admin):**
44
45
  ```powershell
45
- Set-ExecutionPolicy Bypass -Scope Process
46
46
  Invoke-Expression (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/lethevimlet/sshift/main/sshift-install.ps1" -UseBasicParsing).Content
47
47
  ```
48
48
 
@@ -80,10 +80,9 @@ The recommended way to install sshift - automatically handles updates and autost
80
80
  curl -fsSL https://raw.githubusercontent.com/lethevimlet/sshift/main/sshift-install.sh | bash
81
81
  ```
82
82
 
83
- **Windows (PowerShell):**
83
+ **Windows PowerShell (Admin):**
84
84
 
85
85
  ```powershell
86
- Set-ExecutionPolicy Bypass -Scope Process
87
86
  Invoke-Expression (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/lethevimlet/sshift/main/sshift-install.ps1" -UseBasicParsing).Content
88
87
  ```
89
88
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lethevimlet/sshift",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
5
5
  "main": "src/server/index.js",
6
6
  "bin": {
@@ -73,26 +73,111 @@ function registerSFTPHandlers(socket, io) {
73
73
  }
74
74
  });
75
75
 
76
- // SFTP download
76
+ // SFTP download (streamed)
77
77
  socket.on('sftp-download', async (data) => {
78
78
  try {
79
- const fileData = await sftpManager.download(data.sessionId, data.path);
80
- socket.emit('sftp-download-result', { path: data.path, data: fileData.toString('base64') });
79
+ const { sessionId, path } = data;
80
+ const stats = await sftpManager.stat(sessionId, path);
81
+
82
+ if (stats.isDirectory()) {
83
+ socket.emit('sftp-error', { message: 'Cannot download a directory' });
84
+ return;
85
+ }
86
+
87
+ const fileName = path.split('/').pop();
88
+
89
+ socket.emit('sftp-download-start', {
90
+ sessionId,
91
+ path,
92
+ fileName,
93
+ size: stats.size
94
+ });
95
+
96
+ const stream = sftpManager.getReadStream(sessionId, path);
97
+ const FLUSH_SIZE = 1024 * 1024;
98
+ let buffer = Buffer.alloc(0);
99
+ let bytesDownloaded = 0;
100
+
101
+ stream.on('data', (chunk) => {
102
+ buffer = Buffer.concat([buffer, chunk]);
103
+ bytesDownloaded += chunk.length;
104
+
105
+ if (buffer.length >= FLUSH_SIZE) {
106
+ socket.emit('sftp-download-chunk', {
107
+ sessionId,
108
+ path,
109
+ data: buffer.toString('base64'),
110
+ bytesDownloaded,
111
+ totalBytes: stats.size
112
+ });
113
+ buffer = Buffer.alloc(0);
114
+ }
115
+ });
116
+
117
+ stream.on('end', () => {
118
+ if (buffer.length > 0) {
119
+ socket.emit('sftp-download-chunk', {
120
+ sessionId,
121
+ path,
122
+ data: buffer.toString('base64'),
123
+ bytesDownloaded,
124
+ totalBytes: stats.size
125
+ });
126
+ }
127
+ socket.emit('sftp-download-end', {
128
+ sessionId,
129
+ path,
130
+ fileName,
131
+ success: true
132
+ });
133
+ });
134
+
135
+ stream.on('error', (err) => {
136
+ socket.emit('sftp-error', { message: `Download failed: ${err.message}` });
137
+ });
81
138
  } catch (err) {
82
139
  socket.emit('sftp-error', { message: err.message });
83
140
  }
84
141
  });
85
142
 
86
- // SFTP upload
87
- socket.on('sftp-upload', async (data) => {
143
+ // SFTP upload (chunked)
144
+ socket.on('sftp-upload-start', async (data, callback) => {
88
145
  try {
89
- await sftpManager.upload(data.sessionId, data.path, Buffer.from(data.data, 'base64'));
90
- socket.emit('sftp-upload-result', { path: data.path, success: true });
146
+ const uploadId = sftpManager.uploadStart(
147
+ data.sessionId,
148
+ data.path,
149
+ data.fileName,
150
+ data.fileSize
151
+ );
152
+ callback({ uploadId });
91
153
  } catch (err) {
92
- socket.emit('sftp-error', { message: err.message });
154
+ callback({ error: err.message });
93
155
  }
94
156
  });
95
157
 
158
+ socket.on('sftp-upload-chunk', async (data, callback) => {
159
+ try {
160
+ const result = await sftpManager.uploadChunk(data.uploadId, data.data);
161
+ callback(result);
162
+ } catch (err) {
163
+ callback({ error: err.message });
164
+ }
165
+ });
166
+
167
+ socket.on('sftp-upload-end', async (data, callback) => {
168
+ try {
169
+ const result = await sftpManager.uploadEnd(data.uploadId);
170
+ callback(result);
171
+ } catch (err) {
172
+ callback({ error: err.message });
173
+ }
174
+ });
175
+
176
+ // SFTP upload cancel
177
+ socket.on('sftp-upload-cancel', (data) => {
178
+ sftpManager.uploadCancel(data.uploadId);
179
+ });
180
+
96
181
  // SFTP mkdir
97
182
  socket.on('sftp-mkdir', async (data) => {
98
183
  try {
@@ -6,6 +6,12 @@
6
6
  * - endpoints: REST and WebSocket handlers
7
7
  */
8
8
 
9
+ // Polyfill: util.isDate was removed in Node.js 24+ but ssh2 still depends on it
10
+ const util = require('util');
11
+ if (typeof util.isDate !== 'function') {
12
+ util.isDate = (d) => d instanceof Date;
13
+ }
14
+
9
15
  // Load environment variables from .env files
10
16
  require('./utils/env-loader');
11
17
 
@@ -252,7 +258,8 @@ async function initializeServer() {
252
258
  methods: ["GET", "POST"]
253
259
  },
254
260
  pingTimeout: 60000,
255
- pingInterval: 25000
261
+ pingInterval: 25000,
262
+ maxHttpBufferSize: 5e6
256
263
  });
257
264
 
258
265
  // Socket.IO auth middleware
@@ -3,6 +3,8 @@ const { Client } = require('ssh2');
3
3
  class SFTPManager {
4
4
  constructor() {
5
5
  this.sessions = new Map();
6
+ this.activeUploads = new Map();
7
+ this.nextUploadId = 1;
6
8
  }
7
9
 
8
10
  connect(socket, options) {
@@ -137,6 +139,133 @@ class SFTPManager {
137
139
  });
138
140
  }
139
141
 
142
+ stat(sessionId, path) {
143
+ return new Promise((resolve, reject) => {
144
+ const session = this.sessions.get(sessionId);
145
+ if (!session) {
146
+ reject(new Error('Session not found'));
147
+ return;
148
+ }
149
+
150
+ session.sftp.stat(path, (err, stats) => {
151
+ if (err) {
152
+ reject(err);
153
+ return;
154
+ }
155
+
156
+ resolve({
157
+ size: stats.size,
158
+ modifyTime: stats.mtime * 1000,
159
+ isDirectory: stats.isDirectory(),
160
+ isFile: stats.isFile()
161
+ });
162
+ });
163
+ });
164
+ }
165
+
166
+ getReadStream(sessionId, path) {
167
+ const session = this.sessions.get(sessionId);
168
+ if (!session) {
169
+ throw new Error('Session not found');
170
+ }
171
+ return session.sftp.createReadStream(path);
172
+ }
173
+
174
+ uploadStart(sessionId, path, fileName, fileSize) {
175
+ const session = this.sessions.get(sessionId);
176
+ if (!session) {
177
+ throw new Error('Session not found');
178
+ }
179
+
180
+ const uploadId = String(this.nextUploadId++);
181
+ const stream = session.sftp.createWriteStream(path);
182
+
183
+ const upload = {
184
+ id: uploadId,
185
+ stream,
186
+ bytesWritten: 0,
187
+ totalBytes: fileSize,
188
+ fileName,
189
+ path,
190
+ error: null,
191
+ resolveEnd: null,
192
+ rejectEnd: null
193
+ };
194
+
195
+ stream.on('error', (err) => {
196
+ upload.error = err;
197
+ if (upload.rejectEnd) {
198
+ upload.rejectEnd(err);
199
+ upload.rejectEnd = null;
200
+ upload.resolveEnd = null;
201
+ }
202
+ this.activeUploads.delete(uploadId);
203
+ });
204
+
205
+ stream.on('close', () => {
206
+ if (upload.resolveEnd) {
207
+ upload.resolveEnd({ path: upload.path, fileName: upload.fileName });
208
+ upload.resolveEnd = null;
209
+ upload.rejectEnd = null;
210
+ }
211
+ this.activeUploads.delete(uploadId);
212
+ });
213
+
214
+ this.activeUploads.set(uploadId, upload);
215
+ return uploadId;
216
+ }
217
+
218
+ uploadChunk(uploadId, chunkBase64) {
219
+ return new Promise((resolve, reject) => {
220
+ const upload = this.activeUploads.get(uploadId);
221
+ if (!upload) {
222
+ reject(new Error('Upload not found'));
223
+ return;
224
+ }
225
+ if (upload.error) {
226
+ reject(upload.error);
227
+ return;
228
+ }
229
+
230
+ const chunkData = Buffer.from(chunkBase64, 'base64');
231
+
232
+ upload.stream.write(chunkData, () => {
233
+ upload.bytesWritten += chunkData.length;
234
+ resolve({
235
+ bytesWritten: upload.bytesWritten,
236
+ totalBytes: upload.totalBytes
237
+ });
238
+ });
239
+ });
240
+ }
241
+
242
+ uploadEnd(uploadId) {
243
+ return new Promise((resolve, reject) => {
244
+ const upload = this.activeUploads.get(uploadId);
245
+ if (!upload) {
246
+ reject(new Error('Upload not found'));
247
+ return;
248
+ }
249
+ if (upload.error) {
250
+ this.activeUploads.delete(uploadId);
251
+ reject(upload.error);
252
+ return;
253
+ }
254
+
255
+ upload.resolveEnd = resolve;
256
+ upload.rejectEnd = reject;
257
+ upload.stream.end();
258
+ });
259
+ }
260
+
261
+ uploadCancel(uploadId) {
262
+ const upload = this.activeUploads.get(uploadId);
263
+ if (upload) {
264
+ upload.stream.destroy();
265
+ this.activeUploads.delete(uploadId);
266
+ }
267
+ }
268
+
140
269
  download(sessionId, path) {
141
270
  return new Promise((resolve, reject) => {
142
271
  const session = this.sessions.get(sessionId);
@@ -3026,6 +3026,7 @@ body.dragging-tabs .tabs-container {
3026
3026
  border-radius: var(--radius-md);
3027
3027
  overflow-y: auto;
3028
3028
  margin-top: 12px;
3029
+ position: relative;
3029
3030
  }
3030
3031
 
3031
3032
  .sftp-file-item {
@@ -3074,6 +3075,117 @@ body.dragging-tabs .tabs-container {
3074
3075
  margin-left: 12px;
3075
3076
  }
3076
3077
 
3078
+ .sftp-transfer-progress {
3079
+ margin-top: 8px;
3080
+ padding: 8px 12px;
3081
+ background: var(--bg-tertiary);
3082
+ border: 1px solid var(--border-color);
3083
+ border-radius: var(--radius-md);
3084
+ }
3085
+
3086
+ .sftp-transfer-info {
3087
+ display: flex;
3088
+ align-items: center;
3089
+ gap: 8px;
3090
+ margin-bottom: 6px;
3091
+ font-size: 13px;
3092
+ }
3093
+
3094
+ .sftp-transfer-icon {
3095
+ color: var(--accent-primary);
3096
+ width: 16px;
3097
+ text-align: center;
3098
+ }
3099
+
3100
+ .sftp-transfer-filename {
3101
+ flex: 1;
3102
+ white-space: nowrap;
3103
+ overflow: hidden;
3104
+ text-overflow: ellipsis;
3105
+ color: var(--text-primary);
3106
+ min-width: 0;
3107
+ }
3108
+
3109
+ .sftp-transfer-count {
3110
+ color: var(--text-secondary);
3111
+ font-size: 12px;
3112
+ white-space: nowrap;
3113
+ }
3114
+
3115
+ .sftp-transfer-size {
3116
+ color: var(--text-secondary);
3117
+ font-size: 12px;
3118
+ white-space: nowrap;
3119
+ }
3120
+
3121
+ .sftp-transfer-percent {
3122
+ color: var(--text-primary);
3123
+ font-weight: 600;
3124
+ font-size: 13px;
3125
+ min-width: 40px;
3126
+ text-align: right;
3127
+ white-space: nowrap;
3128
+ }
3129
+
3130
+ .sftp-transfer-cancel {
3131
+ background: none;
3132
+ border: none;
3133
+ color: var(--text-secondary);
3134
+ cursor: pointer;
3135
+ padding: 2px 4px;
3136
+ font-size: 14px;
3137
+ line-height: 1;
3138
+ opacity: 0.7;
3139
+ transition: opacity 0.15s, color 0.15s;
3140
+ flex-shrink: 0;
3141
+ }
3142
+
3143
+ .sftp-transfer-cancel:hover {
3144
+ opacity: 1;
3145
+ color: var(--accent-danger, #e74c3c);
3146
+ }
3147
+
3148
+ .sftp-transfer-bar {
3149
+ height: 4px;
3150
+ background: var(--bg-secondary);
3151
+ border-radius: 2px;
3152
+ overflow: hidden;
3153
+ }
3154
+
3155
+ .sftp-transfer-bar-fill {
3156
+ height: 100%;
3157
+ background: var(--accent-primary);
3158
+ border-radius: 2px;
3159
+ transition: width 0.2s ease;
3160
+ }
3161
+
3162
+ .sftp-container.drag-over .sftp-file-list {
3163
+ border-color: var(--accent-primary) !important;
3164
+ background: rgba(0, 123, 255, 0.05) !important;
3165
+ }
3166
+
3167
+ .sftp-container.drag-over .sftp-file-list::after {
3168
+ content: 'Drop files here to upload';
3169
+ position: absolute;
3170
+ top: 50%;
3171
+ left: 50%;
3172
+ transform: translate(-50%, -50%);
3173
+ color: var(--text-secondary);
3174
+ font-size: 14px;
3175
+ pointer-events: none;
3176
+ }
3177
+
3178
+ .sftp-file-list.drag-over::after {
3179
+ content: 'Drop files here to upload';
3180
+ position: absolute;
3181
+ top: 50%;
3182
+ left: 50%;
3183
+ transform: translate(-50%, -50%);
3184
+ color: var(--text-secondary);
3185
+ font-size: 14px;
3186
+ pointer-events: none;
3187
+ }
3188
+
3077
3189
  /* Toast Notifications */
3078
3190
  .toast-container {
3079
3191
  position: fixed;
@@ -3083,6 +3195,9 @@ body.dragging-tabs .tabs-container {
3083
3195
  display: flex;
3084
3196
  flex-direction: column;
3085
3197
  gap: 8px;
3198
+ max-height: calc(100vh - 40px);
3199
+ overflow-y: auto;
3200
+ pointer-events: none;
3086
3201
  }
3087
3202
 
3088
3203
  .toast {
@@ -3333,6 +3448,16 @@ body.dragging-tabs .tabs-container {
3333
3448
  justify-content: center;
3334
3449
  }
3335
3450
 
3451
+ .sftp-transfer-info {
3452
+ flex-wrap: wrap;
3453
+ }
3454
+
3455
+ .sftp-transfer-cancel {
3456
+ font-size: 16px;
3457
+ padding: 4px 6px;
3458
+ margin-left: 4px;
3459
+ }
3460
+
3336
3461
  .special-keys-grid {
3337
3462
  grid-template-columns: repeat(4, 1fr);
3338
3463
  }
@@ -3358,14 +3358,17 @@ const wheelHandler = (e) => {
3358
3358
  setupSocketListeners() {
3359
3359
  this.socket.on('connect', () => {
3360
3360
  console.log('[SSHIFT] Connected to server, socket ID:', this.socket.id);
3361
- this.showToast('Connected to server', 'success');
3362
- // Reload bookmarks to sync any changes that happened while disconnected
3361
+ if (!this.isUpdating) {
3362
+ this.showToast('Connected to server', 'success');
3363
+ }
3363
3364
  this.loadBookmarks();
3364
3365
  });
3365
3366
 
3366
3367
  this.socket.on('disconnect', (reason) => {
3367
3368
  console.log('[SSHIFT] Disconnected from server:', reason);
3368
- this.showToast('Disconnected from server: ' + reason, 'error');
3369
+ if (!this.isUpdating) {
3370
+ this.showToast('Disconnected from server: ' + reason, 'error');
3371
+ }
3369
3372
  });
3370
3373
 
3371
3374
  this.socket.on('connect_error', (error) => {
@@ -3374,7 +3377,7 @@ const wheelHandler = (e) => {
3374
3377
  this.authToken = null;
3375
3378
  localStorage.removeItem('sshift_auth_token');
3376
3379
  this.showLockScreen();
3377
- } else {
3380
+ } else if (!this.isUpdating) {
3378
3381
  this.showToast('Connection error: ' + error.message, 'error');
3379
3382
  }
3380
3383
  });
@@ -3986,15 +3989,56 @@ const wheelHandler = (e) => {
3986
3989
 
3987
3990
  this.socket.on('sftp-error', (data) => {
3988
3991
  this.showToast(data.message, 'error');
3992
+ if (this._activeDownload) {
3993
+ this.hideTransferProgress(this._activeDownload.sessionId);
3994
+ this._activeDownload = null;
3995
+ }
3989
3996
  });
3990
3997
 
3991
- this.socket.on('sftp-download-result', (data) => {
3992
- this.downloadFile(data.path, data.data);
3998
+ this.socket.on('sftp-download-start', (data) => {
3999
+ this._activeDownload = {
4000
+ sessionId: data.sessionId,
4001
+ path: data.path,
4002
+ fileName: data.fileName,
4003
+ totalBytes: data.size,
4004
+ bytesDownloaded: 0,
4005
+ chunks: []
4006
+ };
4007
+ this.showTransferProgress(data.sessionId, data.fileName, 0, 0, data.size, 0, 0, false);
3993
4008
  });
3994
4009
 
3995
- this.socket.on('sftp-upload-result', (data) => {
3996
- this.showToast(`File uploaded: ${data.path}`, 'success');
3997
- this.refreshSFTP();
4010
+ this.socket.on('sftp-download-chunk', (data) => {
4011
+ const dl = this._activeDownload;
4012
+ if (dl && dl.path === data.path) {
4013
+ const binaryStr = atob(data.data);
4014
+ const bytes = new Uint8Array(binaryStr.length);
4015
+ for (let i = 0; i < binaryStr.length; i++) {
4016
+ bytes[i] = binaryStr.charCodeAt(i);
4017
+ }
4018
+ dl.chunks.push(bytes);
4019
+ dl.bytesDownloaded = data.bytesDownloaded;
4020
+ dl.totalBytes = data.totalBytes;
4021
+ const percent = data.totalBytes > 0 ? Math.round((data.bytesDownloaded / data.totalBytes) * 100) : 0;
4022
+ this.showTransferProgress(dl.sessionId, dl.fileName, percent, data.bytesDownloaded, data.totalBytes, 0, 0, false);
4023
+ }
4024
+ });
4025
+
4026
+ this.socket.on('sftp-download-end', (data) => {
4027
+ const dl = this._activeDownload;
4028
+ if (dl && dl.path === data.path) {
4029
+ if (data.success) {
4030
+ const blob = new Blob(dl.chunks, { type: 'application/octet-stream' });
4031
+ const url = URL.createObjectURL(blob);
4032
+ const a = document.createElement('a');
4033
+ a.href = url;
4034
+ a.download = dl.fileName;
4035
+ a.click();
4036
+ URL.revokeObjectURL(url);
4037
+ this.showToast(`Downloaded: ${dl.fileName}`, 'success');
4038
+ }
4039
+ this.hideTransferProgress(dl.sessionId);
4040
+ this._activeDownload = null;
4041
+ }
3998
4042
  });
3999
4043
 
4000
4044
  // Bookmark sync events
@@ -7382,6 +7426,38 @@ const wheelHandler = (e) => {
7382
7426
  this.uploadFile(sessionId);
7383
7427
  });
7384
7428
 
7429
+ const fileList = container.querySelector('.sftp-file-list');
7430
+ fileList.addEventListener('dragover', (e) => {
7431
+ e.preventDefault();
7432
+ e.stopPropagation();
7433
+ container.classList.add('drag-over');
7434
+ });
7435
+
7436
+ fileList.addEventListener('dragenter', (e) => {
7437
+ e.preventDefault();
7438
+ e.stopPropagation();
7439
+ container.classList.add('drag-over');
7440
+ });
7441
+
7442
+ fileList.addEventListener('dragleave', (e) => {
7443
+ e.preventDefault();
7444
+ e.stopPropagation();
7445
+ if (!container.contains(e.relatedTarget)) {
7446
+ container.classList.remove('drag-over');
7447
+ }
7448
+ });
7449
+
7450
+ fileList.addEventListener('drop', (e) => {
7451
+ e.preventDefault();
7452
+ e.stopPropagation();
7453
+ container.classList.remove('drag-over');
7454
+ const files = Array.from(e.dataTransfer.files);
7455
+ if (files.length === 0) return;
7456
+ const pathInput2 = container.querySelector('.sftp-path-input');
7457
+ if (!pathInput2) return;
7458
+ this.uploadFiles(sessionId, files, pathInput2.value);
7459
+ });
7460
+
7385
7461
  wrapper.appendChild(container);
7386
7462
  return wrapper;
7387
7463
  }
@@ -7583,38 +7659,193 @@ const wheelHandler = (e) => {
7583
7659
  uploadFile(sessionId) {
7584
7660
  const input = document.createElement('input');
7585
7661
  input.type = 'file';
7586
- input.onchange = (e) => {
7587
- const file = e.target.files[0];
7588
- if (file) {
7589
- const reader = new FileReader();
7590
- reader.onload = (event) => {
7591
- const pathInput = document.querySelector(`#sftp-${sessionId} .sftp-path-input`);
7592
-
7593
- if (pathInput) {
7594
- const path = pathInput.value;
7595
- const remotePath = path === '/' ? `/${file.name}` : `${path}/${file.name}`;
7596
- this.socket.emit('sftp-upload', {
7597
- sessionId,
7598
- path: remotePath,
7599
- data: btoa(event.target.result)
7600
- });
7601
- }
7602
- };
7603
- reader.readAsBinaryString(file);
7604
- }
7605
- };
7662
+ input.multiple = true;
7663
+ input.style.display = 'none';
7664
+ document.body.appendChild(input);
7665
+ input.addEventListener('change', (e) => {
7666
+ const files = Array.from(e.target.files);
7667
+ document.body.removeChild(input);
7668
+ if (files.length === 0) return;
7669
+ const pathInput = document.querySelector(`#sftp-${sessionId} .sftp-path-input`);
7670
+ if (!pathInput) return;
7671
+ const dirPath = pathInput.value;
7672
+ this.uploadFiles(sessionId, files, dirPath);
7673
+ });
7674
+ input.addEventListener('cancel', () => {
7675
+ document.body.removeChild(input);
7676
+ });
7606
7677
  input.click();
7607
7678
  }
7608
7679
 
7609
- downloadFile(path, data) {
7610
- const filename = path.split('/').pop();
7611
- const blob = new Blob([atob(data)], { type: 'application/octet-stream' });
7612
- const url = URL.createObjectURL(blob);
7613
- const a = document.createElement('a');
7614
- a.href = url;
7615
- a.download = filename;
7616
- a.click();
7617
- URL.revokeObjectURL(url);
7680
+ async uploadFiles(sessionId, files, dirPath) {
7681
+ if (!this._activeUploads) this._activeUploads = new Map();
7682
+
7683
+ for (let i = 0; i < files.length; i++) {
7684
+ try {
7685
+ await this.uploadSingleFile(sessionId, files[i], dirPath, i + 1, files.length);
7686
+ } catch (err) {
7687
+ if (err.message === 'cancelled') {
7688
+ return;
7689
+ }
7690
+ this.showToast(`Upload failed: ${files[i].name} - ${err.message}`, 'error');
7691
+ this.hideTransferProgress(sessionId);
7692
+ break;
7693
+ }
7694
+ }
7695
+ }
7696
+
7697
+ async uploadSingleFile(sessionId, file, dirPath, fileIndex, totalFiles) {
7698
+ const CHUNK_SIZE = 1024 * 1024;
7699
+ const remotePath = dirPath === '/' ? `/${file.name}` : `${dirPath}/${file.name}`;
7700
+
7701
+ this.showTransferProgress(sessionId, file.name, 0, 0, file.size, fileIndex, totalFiles, true);
7702
+
7703
+ try {
7704
+ const uploadId = await new Promise((resolve, reject) => {
7705
+ this.socket.emit('sftp-upload-start', {
7706
+ sessionId,
7707
+ path: remotePath,
7708
+ fileName: file.name,
7709
+ fileSize: file.size
7710
+ }, (response) => {
7711
+ if (response.error) reject(new Error(response.error));
7712
+ else resolve(response.uploadId);
7713
+ });
7714
+ });
7715
+
7716
+ this._activeUploads.set(sessionId, { uploadId, cancelled: false });
7717
+
7718
+ let offset = 0;
7719
+ while (offset < file.size) {
7720
+ const upload = this._activeUploads.get(sessionId);
7721
+ if (!upload || upload.cancelled) {
7722
+ throw new Error('cancelled');
7723
+ }
7724
+
7725
+ const end = Math.min(offset + CHUNK_SIZE, file.size);
7726
+ const slice = file.slice(offset, end);
7727
+ const chunkData = await this.readFileAsBase64(slice);
7728
+
7729
+ const result = await new Promise((resolve, reject) => {
7730
+ this.socket.emit('sftp-upload-chunk', {
7731
+ sessionId,
7732
+ uploadId,
7733
+ data: chunkData
7734
+ }, (response) => {
7735
+ if (response.error) reject(new Error(response.error));
7736
+ else resolve(response);
7737
+ });
7738
+ });
7739
+
7740
+ offset = end;
7741
+ const percent = file.size > 0 ? Math.round((offset / file.size) * 100) : 100;
7742
+ this.showTransferProgress(sessionId, file.name, percent, offset, file.size, fileIndex, totalFiles, true);
7743
+ }
7744
+
7745
+ const upload = this._activeUploads.get(sessionId);
7746
+ if (!upload || upload.cancelled) {
7747
+ throw new Error('cancelled');
7748
+ }
7749
+
7750
+ await new Promise((resolve, reject) => {
7751
+ this.socket.emit('sftp-upload-end', {
7752
+ sessionId,
7753
+ uploadId
7754
+ }, (response) => {
7755
+ if (response.error) reject(new Error(response.error));
7756
+ else resolve(response);
7757
+ });
7758
+ });
7759
+
7760
+ this._activeUploads.delete(sessionId);
7761
+ this.hideTransferProgress(sessionId);
7762
+ this.showToast(`Uploaded: ${file.name}`, 'success');
7763
+ this.refreshSFTP(sessionId);
7764
+ } catch (err) {
7765
+ this._activeUploads.delete(sessionId);
7766
+ this.hideTransferProgress(sessionId);
7767
+ throw err;
7768
+ }
7769
+ }
7770
+
7771
+ readFileAsBase64(blob) {
7772
+ return new Promise((resolve, reject) => {
7773
+ const reader = new FileReader();
7774
+ reader.onload = () => {
7775
+ const dataUrl = reader.result;
7776
+ const base64 = dataUrl.substring(dataUrl.indexOf(',') + 1);
7777
+ resolve(base64);
7778
+ };
7779
+ reader.onerror = reject;
7780
+ reader.readAsDataURL(blob);
7781
+ });
7782
+ }
7783
+
7784
+ showTransferProgress(sessionId, fileName, percent, transferred, total, fileIndex, totalFiles, isUpload) {
7785
+ let progressEl = document.querySelector(`#sftp-${sessionId} .sftp-transfer-progress`);
7786
+ const container = document.querySelector(`#sftp-${sessionId}`);
7787
+
7788
+ if (!container) return;
7789
+
7790
+ if (!progressEl) {
7791
+ progressEl = document.createElement('div');
7792
+ progressEl.className = 'sftp-transfer-progress';
7793
+ progressEl.innerHTML = `
7794
+ <div class="sftp-transfer-info">
7795
+ <span class="sftp-transfer-icon"><i class="fas fa-${isUpload ? 'upload' : 'download'}"></i></span>
7796
+ <span class="sftp-transfer-filename"></span>
7797
+ <span class="sftp-transfer-count"></span>
7798
+ <span class="sftp-transfer-size"></span>
7799
+ <span class="sftp-transfer-percent"></span>
7800
+ <button class="sftp-transfer-cancel" title="Cancel"><i class="fas fa-times"></i></button>
7801
+ </div>
7802
+ <div class="sftp-transfer-bar">
7803
+ <div class="sftp-transfer-bar-fill"></div>
7804
+ </div>
7805
+ `;
7806
+ const fileList = container.querySelector('.sftp-file-list');
7807
+ if (fileList) {
7808
+ container.insertBefore(progressEl, fileList);
7809
+ }
7810
+ const cancelBtn = progressEl.querySelector('.sftp-transfer-cancel');
7811
+ cancelBtn.addEventListener('click', () => {
7812
+ this.cancelTransfer(sessionId);
7813
+ });
7814
+ }
7815
+
7816
+ progressEl.querySelector('.sftp-transfer-icon').innerHTML = `<i class="fas fa-${isUpload ? 'upload' : 'download'}"></i>`;
7817
+ progressEl.querySelector('.sftp-transfer-filename').textContent = fileName;
7818
+ progressEl.querySelector('.sftp-transfer-filename').title = fileName;
7819
+ progressEl.querySelector('.sftp-transfer-count').textContent = totalFiles > 1 ? `${fileIndex} / ${totalFiles}` : '';
7820
+ const sizeText = total > 0 ? `${this.formatSize(transferred)} / ${this.formatSize(total)}` : this.formatSize(transferred);
7821
+ progressEl.querySelector('.sftp-transfer-size').textContent = sizeText;
7822
+ progressEl.querySelector('.sftp-transfer-percent').textContent = `${percent}%`;
7823
+ progressEl.querySelector('.sftp-transfer-bar-fill').style.width = `${percent}%`;
7824
+ progressEl.style.display = '';
7825
+ }
7826
+
7827
+ cancelTransfer(sessionId) {
7828
+ const upload = this._activeUploads && this._activeUploads.get(sessionId);
7829
+ if (upload) {
7830
+ upload.cancelled = true;
7831
+ this._activeUploads.delete(sessionId);
7832
+ this.socket.emit('sftp-upload-cancel', { sessionId, uploadId: upload.uploadId });
7833
+ }
7834
+
7835
+ const download = this._activeDownload;
7836
+ if (download && download.sessionId === sessionId) {
7837
+ this._activeDownload = null;
7838
+ }
7839
+
7840
+ this.hideTransferProgress(sessionId);
7841
+ this.showToast('Transfer cancelled', 'error');
7842
+ }
7843
+
7844
+ hideTransferProgress(sessionId) {
7845
+ const progressEl = document.querySelector(`#sftp-${sessionId} .sftp-transfer-progress`);
7846
+ if (progressEl) {
7847
+ progressEl.remove();
7848
+ }
7618
7849
  }
7619
7850
 
7620
7851
  // Tab Management
@@ -10165,7 +10396,20 @@ async syncTabsFromServer(tabs) {
10165
10396
 
10166
10397
  // Toast Notifications
10167
10398
  showToast(message, type = 'info') {
10399
+ const MAX_TOASTS = 5;
10400
+ const DEDUP_INTERVAL = 3000;
10168
10401
  const container = document.getElementById('toastContainer');
10402
+
10403
+ if (!this._toastDedup) this._toastDedup = new Map();
10404
+ const dedupKey = `${type}:${message}`;
10405
+ const lastShown = this._toastDedup.get(dedupKey);
10406
+ if (lastShown && Date.now() - lastShown < DEDUP_INTERVAL) return;
10407
+ this._toastDedup.set(dedupKey, Date.now());
10408
+
10409
+ while (container.children.length >= MAX_TOASTS) {
10410
+ container.firstChild.remove();
10411
+ }
10412
+
10169
10413
  const toast = document.createElement('div');
10170
10414
  toast.className = `toast ${type}`;
10171
10415
 
@@ -10328,6 +10572,7 @@ async syncTabsFromServer(tabs) {
10328
10572
  }
10329
10573
 
10330
10574
  async executeUpdate() {
10575
+ this.isUpdating = true;
10331
10576
  const updateBtn = document.getElementById('updateBtn');
10332
10577
  const updateOverlay = document.getElementById('updateOverlay');
10333
10578
  const updateMessage = document.getElementById('updateMessage');
@@ -10388,6 +10633,7 @@ async syncTabsFromServer(tabs) {
10388
10633
  }
10389
10634
  } catch (error) {
10390
10635
  console.error('Failed to execute update:', error);
10636
+ this.isUpdating = false;
10391
10637
 
10392
10638
  // Hide overlay on error
10393
10639
  if (updateOverlay) {
@@ -10529,6 +10775,7 @@ async syncTabsFromServer(tabs) {
10529
10775
  }
10530
10776
 
10531
10777
  handleUpdateError(message) {
10778
+ this.isUpdating = false;
10532
10779
  const updateOverlay = document.getElementById('updateOverlay');
10533
10780
  const updateBtn = document.getElementById('updateBtn');
10534
10781
 
@@ -56,6 +56,9 @@ class MobileTerminalHandler {
56
56
  this.hiddenTextarea = null;
57
57
  this._isComposing = false;
58
58
  this._compositionText = '';
59
+ this._compositionEndTs = 0;
60
+ this._lastSentInput = '';
61
+ this._lastSentInputTs = 0;
59
62
  this.contextMenuUserPositioned = false; // Track if user has manually positioned the menu
60
63
 
61
64
  // Configuration
@@ -467,12 +470,37 @@ class MobileTerminalHandler {
467
470
  return;
468
471
  }
469
472
 
473
+ // Skip composition-related input events - they are handled by compositionend.
474
+ // e.isComposing is true when the event is part of an active composition.
475
+ // e.inputType checks catch 'insertCompositionText' and 'insertReplacementText'
476
+ // which some browsers fire instead of or alongside composition events.
477
+ if (e.isComposing) {
478
+ return;
479
+ }
480
+
470
481
  if (this._isComposing) {
482
+ this.hiddenTextarea.value = '';
483
+ return;
484
+ }
485
+
486
+ if (e.inputType === 'insertCompositionText' || e.inputType === 'insertReplacementText') {
487
+ this.hiddenTextarea.value = '';
488
+ return;
489
+ }
490
+
491
+ // Guard against double-sending after compositionend.
492
+ // On some browsers/IMEs, an input event fires right after compositionend
493
+ // with the same text. We debounce this by tracking the last composition
494
+ // end time and skipping input events that arrive within a short window.
495
+ if (this._compositionEndTs && (Date.now() - this._compositionEndTs) < 300) {
496
+ this.hiddenTextarea.value = '';
471
497
  return;
472
498
  }
473
499
 
474
500
  if (e.data && !this.touchState.isDragging) {
475
501
  this._sendToTerminal(e.data);
502
+ this._lastSentInput = e.data;
503
+ this._lastSentInputTs = Date.now();
476
504
  this.hiddenTextarea.value = '';
477
505
  }
478
506
  });
@@ -485,6 +513,7 @@ class MobileTerminalHandler {
485
513
  }
486
514
 
487
515
  if (this._isComposing) {
516
+ e.preventDefault();
488
517
  return;
489
518
  }
490
519
 
@@ -525,11 +554,29 @@ class MobileTerminalHandler {
525
554
 
526
555
  this.hiddenTextarea.addEventListener('compositionend', (e) => {
527
556
  this._isComposing = false;
528
- const composed = this.hiddenTextarea.value;
557
+ this._compositionEndTs = Date.now();
558
+ const composed = e.data || this._compositionText;
529
559
  if (composed && !this.touchState.isDragging) {
530
- this._sendToTerminal(composed);
560
+ // Avoid re-sending text that was already sent via an input event
561
+ // that fired before compositionstart (Gboard timing quirk).
562
+ if (this._lastSentInput && (Date.now() - this._lastSentInputTs) < 500) {
563
+ if (composed === this._lastSentInput) {
564
+ this._lastSentInput = '';
565
+ this._lastSentInputTs = 0;
566
+ } else if (composed.startsWith(this._lastSentInput)) {
567
+ this._sendToTerminal(composed.substring(this._lastSentInput.length));
568
+ this._lastSentInput = '';
569
+ this._lastSentInputTs = 0;
570
+ } else {
571
+ this._sendToTerminal(composed);
572
+ }
573
+ } else {
574
+ this._sendToTerminal(composed);
575
+ }
531
576
  }
532
577
  this._compositionText = '';
578
+ this._lastSentInput = '';
579
+ this._lastSentInputTs = 0;
533
580
  this.hiddenTextarea.value = '';
534
581
  });
535
582
  }