Config Web OTA Integration Guide
Overview
This document describes how the OTA GitHub proxy configuration is integrated into the config_web UI.
Architecture
Backend (Go Agent)
-
Config Metadata (
src/agent/internal/agent/config_meta.go)- Defines the
otasection with two fields:github_proxy_url: Select widget with predefined optionsgithub_proxy_url_custom: Text input for custom URLs (conditionally visible)
- Defines the
-
Config Storage (
agent.toml)[ota]github_proxy_url = "https://gh-proxy.com/" -
API Endpoints
GET /api/config-meta- Returns field metadata with enum optionsGET /api/config- Returns current config valuesPOST /api/config- Saves updated config
Frontend (HTML/JavaScript)
The config_web UI dynamically renders form fields based on metadata:
-
Metadata-Driven Rendering
- Fetch metadata from
/api/config-meta - For each section, render fields according to their
Widgettype - Select widgets use the
Enumoptions from metadata - Conditional visibility based on
VisibleWhenrules
- Fetch metadata from
-
OTA Section UI
<div class="section-card" data-section="ota"><h3>OTA Configuration</h3><div class="field"><label>GitHub Proxy</label><select id="ota-github_proxy_url"><option value="">Direct connection (no proxy)</option><option value="https://gh-proxy.com/">gh-proxy.com</option><option value="https://ghfast.top/">ghfast.top</option><option value="custom">Custom proxy URL</option></select><div class="field-hint">Use a proxy to accelerate GitHub downloads in regions with poor connectivity</div></div><div class="field" data-visible-when="ota.github_proxy_url == 'custom'"><label>Custom Proxy URL</label><input type="text"id="ota-github_proxy_url_custom"placeholder="https://your-proxy.example.com/" /><div class="field-hint">Enter the full URL of your GitHub proxy service</div></div></div> -
Value Transformation When saving:
- If
github_proxy_url == "custom", use the value fromgithub_proxy_url_custom - Otherwise, use the selected proxy URL directly
When loading:
- If the value matches a predefined option, select it
- Otherwise, set
github_proxy_url = "custom"and populategithub_proxy_url_custom
- If
Implementation Flow
1. User Opens Config Web
- Browser requests
/api/config-meta - config_web calls
agent config-meta --format=json - Agent returns metadata including OTA section with enum options
- UI renders OTA section with dropdown
2. User Selects Proxy
- User selects "gh-proxy.com" from dropdown
- JavaScript updates form state
- User clicks "Save"
- POST
/api/configwith{"ota": {"github_proxy_url": "https://gh-proxy.com/"}} - config_web writes to
agent.toml
3. User Selects Custom Proxy
- User selects "Custom proxy URL"
- Conditional field appears (via
visibleWhenrule) - User enters custom URL:
https://my-proxy.example.com/ - User clicks "Save"
- Transform logic converts to:
{"ota": {"github_proxy_url": "https://my-proxy.example.com/"}}
4. OTA Uses Configuration
- OTA updater loads
agent.tomlor/userdata/ota/config.json - Reads
github_proxy_urlvalue - Applies proxy to all GitHub URLs during download
Benefits of Metadata-Driven Approach
-
No Hardcoded URLs in Frontend
- Proxy options defined in Go code
- Easy to add/remove options without touching HTML
-
Type Safety
- Metadata schema enforced in Go
- Frontend validation based on metadata
-
Single Source of Truth
- Go code defines both config structure and UI metadata
- No drift between backend validation and frontend rendering
-
Easy Testing
- Test metadata generation:
agent config-meta --format=json - Test config roundtrip:
agent config --config agent.toml
- Test metadata generation:
Example Metadata Output
{
"sections": [
{
"name": "ota",
"fields": [
{
"key": "github_proxy_url",
"widget": "select",
"enum": [
{
"value": "",
"label": "Direct connection (no proxy)"
},
{
"value": "https://gh-proxy.com/",
"label": "gh-proxy.com"
},
{
"value": "https://ghfast.top/",
"label": "ghfast.top"
},
{
"value": "custom",
"label": "Custom proxy URL"
}
],
"default": ""
},
{
"key": "github_proxy_url_custom",
"widget": "text",
"visibleWhen": {
"all": [
{
"field": "ota.github_proxy_url",
"op": "eq",
"value": "custom"
}
]
}
}
]
}
]
}
Future Enhancements
-
Proxy Health Check
- Add "Test Connection" button
- Verify proxy is reachable before saving
-
Proxy Speed Test
- Compare direct vs proxy download speeds
- Recommend fastest option
-
Multiple Proxy Regions
- Add region-specific proxy recommendations
- Auto-select based on device location