mirror of
https://github.com/bunny-lab-io/Borealis.git
synced 2025-10-27 03:21:57 -06:00
Fixed Encoding Issue with Server URL
This commit is contained in:
@@ -503,7 +503,10 @@ function InstallOrUpdate-BorealisAgent {
|
|||||||
if (-not $inputUrl) { $inputUrl = $currentUrl }
|
if (-not $inputUrl) { $inputUrl = $currentUrl }
|
||||||
$inputUrl = $inputUrl.Trim()
|
$inputUrl = $inputUrl.Trim()
|
||||||
if (-not $inputUrl) { $inputUrl = $defaultUrl }
|
if (-not $inputUrl) { $inputUrl = $defaultUrl }
|
||||||
$inputUrl | Out-File -FilePath $serverUrlPath -Encoding utf8 -Force
|
|
||||||
|
# Write UTF-8 without BOM to avoid BOM being read into the URL
|
||||||
|
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
|
||||||
|
[System.IO.File]::WriteAllText($serverUrlPath, $inputUrl, $utf8NoBom)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "`nConfiguring Borealis Agent (tasks)..." -ForegroundColor Blue
|
Write-Host "`nConfiguring Borealis Agent (tasks)..." -ForegroundColor Blue
|
||||||
|
|||||||
@@ -473,20 +473,35 @@ def _settings_dir():
|
|||||||
|
|
||||||
def get_server_url() -> str:
|
def get_server_url() -> str:
|
||||||
"""Return the Borealis server URL from env or Agent/Borealis/Settings/server_url.txt.
|
"""Return the Borealis server URL from env or Agent/Borealis/Settings/server_url.txt.
|
||||||
Fallback to http://localhost:5000 if missing/empty.
|
- Strips UTF-8 BOM and whitespace
|
||||||
|
- Adds http:// if scheme is missing
|
||||||
|
- Falls back to http://localhost:5000 when missing/invalid
|
||||||
"""
|
"""
|
||||||
|
def _sanitize(val: str) -> str:
|
||||||
|
try:
|
||||||
|
s = (val or '').strip().replace('\ufeff', '')
|
||||||
|
if not s:
|
||||||
|
return ''
|
||||||
|
if not (s.lower().startswith('http://') or s.lower().startswith('https://') or s.lower().startswith('ws://') or s.lower().startswith('wss://')):
|
||||||
|
s = 'http://' + s
|
||||||
|
# Remove trailing slash for consistency
|
||||||
|
return s.rstrip('/')
|
||||||
|
except Exception:
|
||||||
|
return ''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
env_url = os.environ.get('BOREALIS_SERVER_URL')
|
env_url = os.environ.get('BOREALIS_SERVER_URL')
|
||||||
if env_url and env_url.strip():
|
if env_url and _sanitize(env_url):
|
||||||
return env_url.strip()
|
return _sanitize(env_url)
|
||||||
# New location
|
# New location
|
||||||
path = os.path.join(_settings_dir(), 'server_url.txt')
|
path = os.path.join(_settings_dir(), 'server_url.txt')
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
try:
|
try:
|
||||||
with open(path, 'r', encoding='utf-8') as f:
|
with open(path, 'r', encoding='utf-8-sig') as f:
|
||||||
txt = (f.read() or '').strip()
|
txt = f.read()
|
||||||
if txt:
|
s = _sanitize(txt)
|
||||||
return txt
|
if s:
|
||||||
|
return s
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
# Prior interim location (Agent/Settings) migration support
|
# Prior interim location (Agent/Settings) migration support
|
||||||
@@ -494,17 +509,18 @@ def get_server_url() -> str:
|
|||||||
project_root = _find_project_root()
|
project_root = _find_project_root()
|
||||||
old_path = os.path.join(project_root, 'Agent', 'Settings', 'server_url.txt')
|
old_path = os.path.join(project_root, 'Agent', 'Settings', 'server_url.txt')
|
||||||
if os.path.isfile(old_path):
|
if os.path.isfile(old_path):
|
||||||
with open(old_path, 'r', encoding='utf-8') as f:
|
with open(old_path, 'r', encoding='utf-8-sig') as f:
|
||||||
txt = (f.read() or '').strip()
|
txt = f.read()
|
||||||
if txt:
|
s = _sanitize(txt)
|
||||||
|
if s:
|
||||||
# Best-effort copy forward to new location so future reads use it
|
# Best-effort copy forward to new location so future reads use it
|
||||||
try:
|
try:
|
||||||
os.makedirs(_settings_dir(), exist_ok=True)
|
os.makedirs(_settings_dir(), exist_ok=True)
|
||||||
with open(path, 'w', encoding='utf-8') as wf:
|
with open(path, 'w', encoding='utf-8') as wf:
|
||||||
wf.write(txt)
|
wf.write(s)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return txt
|
return s
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Reference in New Issue
Block a user