@lethevimlet/sshift 1.1.3 → 1.1.4

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.4",
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;
@@ -3333,6 +3445,16 @@ body.dragging-tabs .tabs-container {
3333
3445
  justify-content: center;
3334
3446
  }
3335
3447
 
3448
+ .sftp-transfer-info {
3449
+ flex-wrap: wrap;
3450
+ }
3451
+
3452
+ .sftp-transfer-cancel {
3453
+ font-size: 16px;
3454
+ padding: 4px 6px;
3455
+ margin-left: 4px;
3456
+ }
3457
+
3336
3458
  .special-keys-grid {
3337
3459
  grid-template-columns: repeat(4, 1fr);
3338
3460
  }
@@ -3986,15 +3986,56 @@ const wheelHandler = (e) => {
3986
3986
 
3987
3987
  this.socket.on('sftp-error', (data) => {
3988
3988
  this.showToast(data.message, 'error');
3989
+ if (this._activeDownload) {
3990
+ this.hideTransferProgress(this._activeDownload.sessionId);
3991
+ this._activeDownload = null;
3992
+ }
3989
3993
  });
3990
3994
 
3991
- this.socket.on('sftp-download-result', (data) => {
3992
- this.downloadFile(data.path, data.data);
3995
+ this.socket.on('sftp-download-start', (data) => {
3996
+ this._activeDownload = {
3997
+ sessionId: data.sessionId,
3998
+ path: data.path,
3999
+ fileName: data.fileName,
4000
+ totalBytes: data.size,
4001
+ bytesDownloaded: 0,
4002
+ chunks: []
4003
+ };
4004
+ this.showTransferProgress(data.sessionId, data.fileName, 0, 0, data.size, 0, 0, false);
3993
4005
  });
3994
4006
 
3995
- this.socket.on('sftp-upload-result', (data) => {
3996
- this.showToast(`File uploaded: ${data.path}`, 'success');
3997
- this.refreshSFTP();
4007
+ this.socket.on('sftp-download-chunk', (data) => {
4008
+ const dl = this._activeDownload;
4009
+ if (dl && dl.path === data.path) {
4010
+ const binaryStr = atob(data.data);
4011
+ const bytes = new Uint8Array(binaryStr.length);
4012
+ for (let i = 0; i < binaryStr.length; i++) {
4013
+ bytes[i] = binaryStr.charCodeAt(i);
4014
+ }
4015
+ dl.chunks.push(bytes);
4016
+ dl.bytesDownloaded = data.bytesDownloaded;
4017
+ dl.totalBytes = data.totalBytes;
4018
+ const percent = data.totalBytes > 0 ? Math.round((data.bytesDownloaded / data.totalBytes) * 100) : 0;
4019
+ this.showTransferProgress(dl.sessionId, dl.fileName, percent, data.bytesDownloaded, data.totalBytes, 0, 0, false);
4020
+ }
4021
+ });
4022
+
4023
+ this.socket.on('sftp-download-end', (data) => {
4024
+ const dl = this._activeDownload;
4025
+ if (dl && dl.path === data.path) {
4026
+ if (data.success) {
4027
+ const blob = new Blob(dl.chunks, { type: 'application/octet-stream' });
4028
+ const url = URL.createObjectURL(blob);
4029
+ const a = document.createElement('a');
4030
+ a.href = url;
4031
+ a.download = dl.fileName;
4032
+ a.click();
4033
+ URL.revokeObjectURL(url);
4034
+ this.showToast(`Downloaded: ${dl.fileName}`, 'success');
4035
+ }
4036
+ this.hideTransferProgress(dl.sessionId);
4037
+ this._activeDownload = null;
4038
+ }
3998
4039
  });
3999
4040
 
4000
4041
  // Bookmark sync events
@@ -6722,6 +6763,14 @@ const wheelHandler = (e) => {
6722
6763
  }
6723
6764
  });
6724
6765
 
6766
+ // Handle binary input (control characters, etc.) that onData may not capture
6767
+ terminal.onBinary((data) => {
6768
+ const sess = this.sessions.get(sessionId);
6769
+ if (sess && sess.connected && sess.isController) {
6770
+ this.socket.emit('ssh-data', { sessionId, data: data });
6771
+ }
6772
+ });
6773
+
6725
6774
  // Handle resize
6726
6775
  terminal.onResize(({ cols, rows }) => {
6727
6776
  const sess = this.sessions.get(sessionId);
@@ -7382,6 +7431,38 @@ const wheelHandler = (e) => {
7382
7431
  this.uploadFile(sessionId);
7383
7432
  });
7384
7433
 
7434
+ const fileList = container.querySelector('.sftp-file-list');
7435
+ fileList.addEventListener('dragover', (e) => {
7436
+ e.preventDefault();
7437
+ e.stopPropagation();
7438
+ container.classList.add('drag-over');
7439
+ });
7440
+
7441
+ fileList.addEventListener('dragenter', (e) => {
7442
+ e.preventDefault();
7443
+ e.stopPropagation();
7444
+ container.classList.add('drag-over');
7445
+ });
7446
+
7447
+ fileList.addEventListener('dragleave', (e) => {
7448
+ e.preventDefault();
7449
+ e.stopPropagation();
7450
+ if (!container.contains(e.relatedTarget)) {
7451
+ container.classList.remove('drag-over');
7452
+ }
7453
+ });
7454
+
7455
+ fileList.addEventListener('drop', (e) => {
7456
+ e.preventDefault();
7457
+ e.stopPropagation();
7458
+ container.classList.remove('drag-over');
7459
+ const files = Array.from(e.dataTransfer.files);
7460
+ if (files.length === 0) return;
7461
+ const pathInput2 = container.querySelector('.sftp-path-input');
7462
+ if (!pathInput2) return;
7463
+ this.uploadFiles(sessionId, files, pathInput2.value);
7464
+ });
7465
+
7385
7466
  wrapper.appendChild(container);
7386
7467
  return wrapper;
7387
7468
  }
@@ -7583,38 +7664,193 @@ const wheelHandler = (e) => {
7583
7664
  uploadFile(sessionId) {
7584
7665
  const input = document.createElement('input');
7585
7666
  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
- };
7667
+ input.multiple = true;
7668
+ input.style.display = 'none';
7669
+ document.body.appendChild(input);
7670
+ input.addEventListener('change', (e) => {
7671
+ const files = Array.from(e.target.files);
7672
+ document.body.removeChild(input);
7673
+ if (files.length === 0) return;
7674
+ const pathInput = document.querySelector(`#sftp-${sessionId} .sftp-path-input`);
7675
+ if (!pathInput) return;
7676
+ const dirPath = pathInput.value;
7677
+ this.uploadFiles(sessionId, files, dirPath);
7678
+ });
7679
+ input.addEventListener('cancel', () => {
7680
+ document.body.removeChild(input);
7681
+ });
7606
7682
  input.click();
7607
7683
  }
7608
7684
 
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);
7685
+ async uploadFiles(sessionId, files, dirPath) {
7686
+ if (!this._activeUploads) this._activeUploads = new Map();
7687
+
7688
+ for (let i = 0; i < files.length; i++) {
7689
+ try {
7690
+ await this.uploadSingleFile(sessionId, files[i], dirPath, i + 1, files.length);
7691
+ } catch (err) {
7692
+ if (err.message === 'cancelled') {
7693
+ return;
7694
+ }
7695
+ this.showToast(`Upload failed: ${files[i].name} - ${err.message}`, 'error');
7696
+ this.hideTransferProgress(sessionId);
7697
+ break;
7698
+ }
7699
+ }
7700
+ }
7701
+
7702
+ async uploadSingleFile(sessionId, file, dirPath, fileIndex, totalFiles) {
7703
+ const CHUNK_SIZE = 1024 * 1024;
7704
+ const remotePath = dirPath === '/' ? `/${file.name}` : `${dirPath}/${file.name}`;
7705
+
7706
+ this.showTransferProgress(sessionId, file.name, 0, 0, file.size, fileIndex, totalFiles, true);
7707
+
7708
+ try {
7709
+ const uploadId = await new Promise((resolve, reject) => {
7710
+ this.socket.emit('sftp-upload-start', {
7711
+ sessionId,
7712
+ path: remotePath,
7713
+ fileName: file.name,
7714
+ fileSize: file.size
7715
+ }, (response) => {
7716
+ if (response.error) reject(new Error(response.error));
7717
+ else resolve(response.uploadId);
7718
+ });
7719
+ });
7720
+
7721
+ this._activeUploads.set(sessionId, { uploadId, cancelled: false });
7722
+
7723
+ let offset = 0;
7724
+ while (offset < file.size) {
7725
+ const upload = this._activeUploads.get(sessionId);
7726
+ if (!upload || upload.cancelled) {
7727
+ throw new Error('cancelled');
7728
+ }
7729
+
7730
+ const end = Math.min(offset + CHUNK_SIZE, file.size);
7731
+ const slice = file.slice(offset, end);
7732
+ const chunkData = await this.readFileAsBase64(slice);
7733
+
7734
+ const result = await new Promise((resolve, reject) => {
7735
+ this.socket.emit('sftp-upload-chunk', {
7736
+ sessionId,
7737
+ uploadId,
7738
+ data: chunkData
7739
+ }, (response) => {
7740
+ if (response.error) reject(new Error(response.error));
7741
+ else resolve(response);
7742
+ });
7743
+ });
7744
+
7745
+ offset = end;
7746
+ const percent = file.size > 0 ? Math.round((offset / file.size) * 100) : 100;
7747
+ this.showTransferProgress(sessionId, file.name, percent, offset, file.size, fileIndex, totalFiles, true);
7748
+ }
7749
+
7750
+ const upload = this._activeUploads.get(sessionId);
7751
+ if (!upload || upload.cancelled) {
7752
+ throw new Error('cancelled');
7753
+ }
7754
+
7755
+ await new Promise((resolve, reject) => {
7756
+ this.socket.emit('sftp-upload-end', {
7757
+ sessionId,
7758
+ uploadId
7759
+ }, (response) => {
7760
+ if (response.error) reject(new Error(response.error));
7761
+ else resolve(response);
7762
+ });
7763
+ });
7764
+
7765
+ this._activeUploads.delete(sessionId);
7766
+ this.hideTransferProgress(sessionId);
7767
+ this.showToast(`Uploaded: ${file.name}`, 'success');
7768
+ this.refreshSFTP(sessionId);
7769
+ } catch (err) {
7770
+ this._activeUploads.delete(sessionId);
7771
+ this.hideTransferProgress(sessionId);
7772
+ throw err;
7773
+ }
7774
+ }
7775
+
7776
+ readFileAsBase64(blob) {
7777
+ return new Promise((resolve, reject) => {
7778
+ const reader = new FileReader();
7779
+ reader.onload = () => {
7780
+ const dataUrl = reader.result;
7781
+ const base64 = dataUrl.substring(dataUrl.indexOf(',') + 1);
7782
+ resolve(base64);
7783
+ };
7784
+ reader.onerror = reject;
7785
+ reader.readAsDataURL(blob);
7786
+ });
7787
+ }
7788
+
7789
+ showTransferProgress(sessionId, fileName, percent, transferred, total, fileIndex, totalFiles, isUpload) {
7790
+ let progressEl = document.querySelector(`#sftp-${sessionId} .sftp-transfer-progress`);
7791
+ const container = document.querySelector(`#sftp-${sessionId}`);
7792
+
7793
+ if (!container) return;
7794
+
7795
+ if (!progressEl) {
7796
+ progressEl = document.createElement('div');
7797
+ progressEl.className = 'sftp-transfer-progress';
7798
+ progressEl.innerHTML = `
7799
+ <div class="sftp-transfer-info">
7800
+ <span class="sftp-transfer-icon"><i class="fas fa-${isUpload ? 'upload' : 'download'}"></i></span>
7801
+ <span class="sftp-transfer-filename"></span>
7802
+ <span class="sftp-transfer-count"></span>
7803
+ <span class="sftp-transfer-size"></span>
7804
+ <span class="sftp-transfer-percent"></span>
7805
+ <button class="sftp-transfer-cancel" title="Cancel"><i class="fas fa-times"></i></button>
7806
+ </div>
7807
+ <div class="sftp-transfer-bar">
7808
+ <div class="sftp-transfer-bar-fill"></div>
7809
+ </div>
7810
+ `;
7811
+ const fileList = container.querySelector('.sftp-file-list');
7812
+ if (fileList) {
7813
+ container.insertBefore(progressEl, fileList);
7814
+ }
7815
+ const cancelBtn = progressEl.querySelector('.sftp-transfer-cancel');
7816
+ cancelBtn.addEventListener('click', () => {
7817
+ this.cancelTransfer(sessionId);
7818
+ });
7819
+ }
7820
+
7821
+ progressEl.querySelector('.sftp-transfer-icon').innerHTML = `<i class="fas fa-${isUpload ? 'upload' : 'download'}"></i>`;
7822
+ progressEl.querySelector('.sftp-transfer-filename').textContent = fileName;
7823
+ progressEl.querySelector('.sftp-transfer-filename').title = fileName;
7824
+ progressEl.querySelector('.sftp-transfer-count').textContent = totalFiles > 1 ? `${fileIndex} / ${totalFiles}` : '';
7825
+ const sizeText = total > 0 ? `${this.formatSize(transferred)} / ${this.formatSize(total)}` : this.formatSize(transferred);
7826
+ progressEl.querySelector('.sftp-transfer-size').textContent = sizeText;
7827
+ progressEl.querySelector('.sftp-transfer-percent').textContent = `${percent}%`;
7828
+ progressEl.querySelector('.sftp-transfer-bar-fill').style.width = `${percent}%`;
7829
+ progressEl.style.display = '';
7830
+ }
7831
+
7832
+ cancelTransfer(sessionId) {
7833
+ const upload = this._activeUploads && this._activeUploads.get(sessionId);
7834
+ if (upload) {
7835
+ upload.cancelled = true;
7836
+ this._activeUploads.delete(sessionId);
7837
+ this.socket.emit('sftp-upload-cancel', { sessionId, uploadId: upload.uploadId });
7838
+ }
7839
+
7840
+ const download = this._activeDownload;
7841
+ if (download && download.sessionId === sessionId) {
7842
+ this._activeDownload = null;
7843
+ }
7844
+
7845
+ this.hideTransferProgress(sessionId);
7846
+ this.showToast('Transfer cancelled', 'error');
7847
+ }
7848
+
7849
+ hideTransferProgress(sessionId) {
7850
+ const progressEl = document.querySelector(`#sftp-${sessionId} .sftp-transfer-progress`);
7851
+ if (progressEl) {
7852
+ progressEl.remove();
7853
+ }
7618
7854
  }
7619
7855
 
7620
7856
  // Tab Management
@@ -56,6 +56,7 @@ class MobileTerminalHandler {
56
56
  this.hiddenTextarea = null;
57
57
  this._isComposing = false;
58
58
  this._compositionText = '';
59
+ this._compositionEndTs = 0;
59
60
  this.contextMenuUserPositioned = false; // Track if user has manually positioned the menu
60
61
 
61
62
  // Configuration
@@ -471,6 +472,15 @@ class MobileTerminalHandler {
471
472
  return;
472
473
  }
473
474
 
475
+ // Guard against double-sending after compositionend.
476
+ // On some browsers/IMEs, an input event fires right after compositionend
477
+ // with the same text. We debounce this by tracking the last composition
478
+ // end time and skipping input events that arrive within a short window.
479
+ if (this._compositionEndTs && (Date.now() - this._compositionEndTs) < 300) {
480
+ this.hiddenTextarea.value = '';
481
+ return;
482
+ }
483
+
474
484
  if (e.data && !this.touchState.isDragging) {
475
485
  this._sendToTerminal(e.data);
476
486
  this.hiddenTextarea.value = '';
@@ -485,6 +495,7 @@ class MobileTerminalHandler {
485
495
  }
486
496
 
487
497
  if (this._isComposing) {
498
+ e.preventDefault();
488
499
  return;
489
500
  }
490
501
 
@@ -525,7 +536,8 @@ class MobileTerminalHandler {
525
536
 
526
537
  this.hiddenTextarea.addEventListener('compositionend', (e) => {
527
538
  this._isComposing = false;
528
- const composed = this.hiddenTextarea.value;
539
+ this._compositionEndTs = Date.now();
540
+ const composed = e.data || this.hiddenTextarea.value;
529
541
  if (composed && !this.touchState.isDragging) {
530
542
  this._sendToTerminal(composed);
531
543
  }