@lethevimlet/sshift 0.9.7 → 0.9.8

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": "0.9.7",
3
+ "version": "0.9.8",
4
4
  "description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
5
5
  "main": "src/server/index.js",
6
6
  "bin": {
@@ -45,7 +45,8 @@ const defaultConfig = {
45
45
 
46
46
  /**
47
47
  * Ensure a config file exists. If no config is found in any search path,
48
- * create config.json in the package root using env var overrides or defaults.
48
+ * create config.json at the user install directory (~/.local/share/sshift/.env/config.json)
49
+ * so it survives npm updates (which replace the package directory).
49
50
  * This mirrors the installer create_config behavior.
50
51
  */
51
52
  function ensureConfig() {
@@ -55,7 +56,11 @@ function ensureConfig() {
55
56
  }
56
57
  }
57
58
 
58
- const configPath = path.join(PACKAGE_DIR, 'config.json');
59
+ const configDir = path.join(USER_INSTALL_DIR, '.env');
60
+ if (!fs.existsSync(configDir)) {
61
+ fs.mkdirSync(configDir, { recursive: true });
62
+ }
63
+ const configPath = path.join(configDir, 'config.json');
59
64
  const config = { ...defaultConfig };
60
65
 
61
66
  if (process.env.PORT) {
@@ -85,8 +90,8 @@ function getConfigPath() {
85
90
  }
86
91
  }
87
92
 
88
- // Return default path (first user install directory)
89
- const defaultPath = ENV_CONFIG_PATHS[0];
93
+ // Return default path (user install directory, survives npm updates)
94
+ const defaultPath = path.join(USER_INSTALL_DIR, '.env', 'config.json');
90
95
  console.log('[CONFIG] Using default path:', defaultPath);
91
96
  return defaultPath;
92
97
  }
@@ -3540,8 +3540,11 @@ const wheelHandler = (e) => {
3540
3540
  let state = data.state;
3541
3541
  if (data.encoded) {
3542
3542
  try {
3543
- // Decode base64 to utf-8 string
3544
- state = atob(data.state);
3543
+ // Decode base64 to UTF-8 string (atob produces Latin-1 binary;
3544
+ // we must re-decode as UTF-8 to preserve multi-byte characters)
3545
+ const binaryString = atob(data.state);
3546
+ const bytes = Uint8Array.from(binaryString, c => c.charCodeAt(0));
3547
+ state = new TextDecoder().decode(bytes);
3545
3548
  console.log('[SSHIFT] Decoded base64 state, size:', state.length);
3546
3549
  } catch (e) {
3547
3550
  console.error('[SSHIFT] Error decoding base64 state:', e);
@@ -562,40 +562,60 @@ function New-Config {
562
562
  $configFile = Join-Path $envDir "config.json"
563
563
  $port = if ($ServerPort -ne "") { $ServerPort } else { "8022" }
564
564
 
565
- $configContent = @"
566
- {
567
- "port": $port,
568
- "devPort": 3000,
569
- "bind": "0.0.0.0",
570
- "enableHttps": true,
571
- "sticky": true,
572
- "sshKeepaliveInterval": 15000,
573
- "sshKeepaliveCountMax": 500,
574
- "bookmarks": [],
575
- "folders": []
576
- }
577
- "@
578
-
579
- # Write config to user install directory (preferred by updated config loader)
580
- $configContent | Out-File -FilePath $configFile -Encoding ASCII
565
+ # Merge default values into existing config:
566
+ # - Preserves user's existing values
567
+ # - Adds new default properties from newer versions
568
+ # - If -port was explicitly set, overrides the port value
569
+ $defaults = @{
570
+ port = [int]$port
571
+ devPort = 3000
572
+ bind = "0.0.0.0"
573
+ enableHttps = $true
574
+ sticky = $true
575
+ sshKeepaliveInterval = 15000
576
+ sshKeepaliveCountMax = 500
577
+ bookmarks = @()
578
+ folders = @()
579
+ }
581
580
 
582
- # Also write config to the npm package directory so the older config loader finds it
583
- $sshiftPath = (Get-Command -Name "sshift" -ErrorAction SilentlyContinue).Source
584
- if ($sshiftPath) {
585
- # sshift is typically at <npm_prefix>\sshift.cmd, package dir is <npm_prefix>\node_modules\@lethevimlet\sshift
586
- $npmPrefix = npm config get prefix 2>$null
587
- if ($npmPrefix) {
588
- $pkgDir = Join-Path $npmPrefix "node_modules\@lethevimlet\sshift"
589
- if (Test-Path $pkgDir) {
590
- $pkgEnvDir = Join-Path $pkgDir ".env"
591
- New-Item -ItemType Directory -Force -Path $pkgEnvDir | Out-Null
592
- $configContent | Out-File -FilePath (Join-Path $pkgEnvDir "config.json") -Encoding ASCII
593
- $configContent | Out-File -FilePath (Join-Path $pkgDir "config.json") -Encoding ASCII
594
- }
581
+ $wasNew = $true
582
+ if (Test-Path $configFile) {
583
+ try {
584
+ $existing = Get-Content $configFile -Raw | ConvertFrom-Json
585
+ $wasNew = $false
586
+ } catch {
587
+ Write-Warning "Could not parse existing config, using defaults"
588
+ $existing = [PSCustomObject]@{}
595
589
  }
590
+ } else {
591
+ $existing = [PSCustomObject]@{}
592
+ }
593
+
594
+ # Build merged config: start with defaults, overlay existing values
595
+ $merged = [PSCustomObject]@{}
596
+ foreach ($key in $defaults.Keys) {
597
+ $merged | Add-Member -NotePropertyName $key -NotePropertyValue $defaults[$key] -Force
598
+ }
599
+ foreach ($prop in $existing.PSObject.Properties) {
600
+ $merged | Add-Member -NotePropertyName $prop.Name -NotePropertyValue $prop.Value -Force
601
+ }
602
+
603
+ # If -port was explicitly set, override the port value
604
+ if ($ServerPort -ne "") {
605
+ $merged.port = [int]$ServerPort
606
+ }
607
+
608
+ # Write merged config
609
+ $merged | ConvertTo-Json -Depth 10 | Set-Content -Path $configFile -Encoding ASCII
610
+
611
+ if ($wasNew) {
612
+ Write-Info "Configuration created at $configFile"
613
+ } else {
614
+ Write-Info "Existing configuration merged with defaults at $configFile"
596
615
  }
597
616
 
598
- Write-Success "Configuration created with HTTPS enabled on port $port"
617
+ $effectivePort = $merged.port
618
+ Write-Success "Configuration created with HTTPS enabled on port $effectivePort"
599
619
  }
600
620
 
601
621
  # Add to PATH
package/sshift-install.sh CHANGED
@@ -411,49 +411,44 @@ create_config() {
411
411
  mkdir -p "$INSTALL_DIR/.env"
412
412
 
413
413
  local port="${SERVER_PORT:-8022}"
414
- local config_content="{
415
- \"port\": $port,
416
- \"devPort\": 3000,
417
- \"bind\": \"0.0.0.0\",
418
- \"enableHttps\": true,
419
- \"sticky\": true,
420
- \"sshKeepaliveInterval\": 15000,
421
- \"sshKeepaliveCountMax\": 500,
422
- \"bookmarks\": [],
423
- \"folders\": []
424
- }"
425
-
426
- # Write config to user install directory (preferred by updated config loader)
427
- echo "$config_content" > "$INSTALL_DIR/.env/config.json"
428
-
429
- # Also write config to the npm package directory so the older config loader finds it
430
- local sshift_bin_path=$(which sshift 2>/dev/null)
431
- if [ -n "$sshift_bin_path" ]; then
432
- local real_path="$sshift_bin_path"
433
- # Resolve symlinks portably (readlink -f is not available on macOS BSD)
434
- while [ -L "$real_path" ]; do
435
- local target=$(readlink "$real_path" 2>/dev/null)
436
- if [ -z "$target" ]; then break; fi
437
- # Handle relative symlinks
438
- case "$target" in
439
- /*) real_path="$target" ;;
440
- *) real_path="$(dirname "$real_path")/$target" ;;
441
- esac
442
- done
443
- local pkg_dir=$(dirname "$real_path")
444
- if [ -d "$pkg_dir" ]; then
445
- if mkdir -p "$pkg_dir/.env" 2>/dev/null; then
446
- echo "$config_content" > "$pkg_dir/.env/config.json"
447
- echo "$config_content" > "$pkg_dir/config.json"
448
- else
449
- # Package directory may be root-owned (e.g. Homebrew npm global installs on macOS)
450
- # The user-space config at INSTALL_DIR is already written, so this is just a
451
- # backwards-compat fallback — skip silently if we lack permissions.
452
- warn "Cannot write to package directory $pkg_dir (permission denied). Using config at $INSTALL_DIR/.env/config.json instead."
453
- fi
454
- fi
414
+ local config_file="$INSTALL_DIR/.env/config.json"
415
+
416
+ # Merge default values into existing config:
417
+ # - Preserves user's existing values
418
+ # - Adds new default properties from newer versions
419
+ # - If --port was explicitly set, overrides the port value
420
+ local port_override=""
421
+ if [ -n "$SERVER_PORT" ]; then
422
+ port_override="$SERVER_PORT"
423
+ fi
424
+
425
+ local config_action
426
+ config_action=$(node -e "
427
+ const fs = require('fs');
428
+ const defaults = {port: $port, devPort: 3000, bind: '0.0.0.0', enableHttps: true, sticky: true, sshKeepaliveInterval: 15000, sshKeepaliveCountMax: 500, bookmarks: [], folders: []};
429
+ const configPath = '$config_file';
430
+ let existing = {};
431
+ let wasNew = true;
432
+ if (fs.existsSync(configPath)) {
433
+ try { existing = JSON.parse(fs.readFileSync(configPath, 'utf8')); wasNew = false; } catch(e) { process.stderr.write('Warning: Could not parse existing config, using defaults\n'); }
434
+ }
435
+ const merged = Object.assign({}, defaults, existing);
436
+ const portOverride = '$port_override';
437
+ if (portOverride) { merged.port = parseInt(portOverride); }
438
+ fs.writeFileSync(configPath, JSON.stringify(merged, null, 2) + '\n');
439
+ process.stdout.write(wasNew ? 'created' : 'merged');
440
+ " 2>&1) || config_action="created"
441
+
442
+ if [ "$config_action" = "merged" ]; then
443
+ info "Existing configuration merged with defaults at $config_file"
444
+ else
445
+ info "Configuration created at $config_file"
455
446
  fi
456
447
 
448
+ local effective_port=$(grep -oP '"port"\s*:\s*\K[0-9]+' "$config_file" 2>/dev/null | head -1)
449
+ if [ -n "$effective_port" ]; then
450
+ port="$effective_port"
451
+ fi
457
452
  success "Configuration created with HTTPS enabled on port $port"
458
453
  }
459
454