@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 +1 -1
- package/src/server/utils/config.js +9 -4
- package/src/webapp/js/app.js +5 -2
- package/sshift-install.ps1 +50 -30
- package/sshift-install.sh +36 -41
package/package.json
CHANGED
|
@@ -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
|
|
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
|
|
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 (
|
|
89
|
-
const defaultPath =
|
|
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
|
}
|
package/src/webapp/js/app.js
CHANGED
|
@@ -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
|
|
3544
|
-
|
|
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);
|
package/sshift-install.ps1
CHANGED
|
@@ -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
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
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
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
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
|
-
|
|
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
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
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
|
|