mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-08 14:14:19 +00:00
3.6 KiB
3.6 KiB
Geofiles Scheduled Update Design
Summary
Add configurable scheduled geofile updates, settable from both the web panel and x-ui.sh. Configuration stored in x-ui.json as the single source of truth.
Configuration
New geofileUpdate group in /etc/x-ui/x-ui.json:
{
"geofileUpdate": {
"enabled": false,
"frequency": "daily",
"hour": 4
}
}
enabled: bool, defaultfalsefrequency:hourly|every12h|daily|weeklyhour: int (0-23), used fordailyandweeklyfrequencies
Backend Job
New file web/job/geofile_update_job.go, following the existing BackupJob pattern:
- Registered as
@every 1minweb/web.gostartTask() Run()checksenabled, thenshouldRun(frequency)for time matchingshouldRun()logic:hourly: minute == 0every12h: (hour == 0 || hour == 12) && minute == 0daily: hour == configuredHour && minute == 0weekly: weekday == Sunday && hour == configuredHour && minute == 0
- On match: if not master node, returns immediately. Otherwise calls
UpdateGeofile("")then bumps shared geo version in DB to notify workers
Files touched
| File | Change |
|---|---|
web/job/geofile_update_job.go |
New file |
web/web.go |
Add cron registration line |
web/service/setting.go |
Add defaultValueMap entries, settingGroups mapping, getter methods |
web/service/server.go |
No changes (UpdateGeofile already exposed) |
Panel API
No new API endpoints needed. Existing POST /panel/api/setting/saveSetting and GET /panel/api/setting/getSetting handle arbitrary settings via settingGroups mapping.
Panel UI
In web/html/index.html, inside the existing Geofiles collapse panel:
- Toggle switch: enabled/disabled
- Frequency dropdown: Hourly / Every 12 hours / Daily / Weekly
- Hour dropdown: 0-23, visible only when frequency is
dailyorweekly
Reuses existing loadSetting() / saveSetting() Vue methods.
New Vue data fields
geofileUpdateEnabled: booleangeofileUpdateFrequency: stringgeofileUpdateHour: number
New i18n keys
geofileUpdate— "Scheduled Update"geofileUpdateEnabled— "Enable Scheduled Update"geofileUpdateFrequency— "Update Frequency"geofileUpdateHour— "Update Hour"- (Chinese translations in
translate.zh_CN.toml)
x-ui.sh
New subcommand geofile-cron:
x-ui geofile-cron --enable --frequency daily --hour 4
x-ui geofile-cron --disable
x-ui geofile-cron --status
- Directly reads/writes
geofileUpdatesection inx-ui.json --statusprints current config to stdout--enablewrites config, prints confirmation, then runssystemctl restart x-ui--disablesetsenabled: false, then runssystemctl restart x-ui- Config file path:
/etc/x-ui/x-ui.json(same asconfig.GetSettingPath())
Multi-Node Behavior
- Job runs on all nodes;
Run()checksIsMasterand returns immediately on workers - After master updates, calls
database.BumpSharedGeoVersion()to notify workers - Worker nodes detect shared version bump via existing
NodeSyncService.syncGeoIfNeeded()and auto-pull
Data Flow
Panel UI ──saveSetting──→ x-ui.json ──read by──→ GeofileUpdateJob.Run()
│
x-ui.sh ──write──→ x-ui.json ──restart──→ panel re-reads settings
Error Handling
- Download failures logged, do not block next scheduled run
geofile_versions.jsononly updated on successful download (existing behavior)- Settings with invalid values fall back to defaults via
defaultValueMap