feat(system): add data auto-sync API for data/ directory#301
Merged
Conversation
Add two new endpoints under /api/v1/system/:
POST /api/v1/system/update-data
Downloads the GitHub archive (branch or tag) and overwrites the
configured data/ sub-directories (fingerprints, vuln, vuln_en,
mcp, eval, agents). Runs asynchronously; supports optional
github_token to avoid rate-limiting and per-call dir selection.
GET /api/v1/system/update-status
Returns current / last sync status: running flag, success bool,
started_at / finished_at timestamps, file count, message.
Implementation:
- common/websocket/update_api.go — handler + sync logic
- common/websocket/update_api_test.go — unit tests (zip extract, dir filter)
- common/websocket/server.go — route registration under /system group
- docs/api_data_update.md — full API documentation with examples
boy-hack
pushed a commit
that referenced
this pull request
Apr 17, 2026
…oken - Replace GitHub archive download (zip) with to avoid the need for a GitHub token. Anonymous git clone works without any rate-limit concerns for a single operation. - Remove the field from UpdateDataRequest entirely. - Add copyDataDirs / copyDir helpers that recursively copy the requested data/ sub-directories from the cloned temp dir to the working dir. - Remove the zip-based extractDataDirs helper (no longer needed). - Rewrite update_api_test.go to test copyDataDirs instead of extractDataDirs. All existing test scenarios are preserved (selective dirs, all dirs, missing sub-dir, splitDirs). - Rewrite docs/api_data_update.md to match the api_zh.md doc style (endpoint info table, request/response tables, curl + python examples). Closes #301
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
systemAPI group that lets operators pull the latest rule files from GitHub without restarting the server or rebuilding the Docker image.New Endpoints
POST/api/v1/system/update-dataGET/api/v1/system/update-statusHow It Works
codeload.github.com(branch or tag)data/sub-directories to diskRequest Options (
POST /system/update-data){ "ref": "main", // branch or tag, default: main "is_tag": false, // true when ref is a tag "github_token": "...", // optional, avoids 60 req/h anon rate limit "dirs": "fingerprints,vuln,vuln_en,mcp,eval,agents" // optional }Files Changed
common/websocket/update_api.go— handler + async sync logic (zip download → extract → overwrite)common/websocket/update_api_test.go— unit tests covering selective extraction, full extraction, invalid zip, dir splittingcommon/websocket/server.go— route registration (/api/v1/systemgroup, identity middleware)docs/api_data_update.md— full API documentation with curl examples, field reference, error table, workflow diagramTest Results
Notes
github_tokenis never logged or persistedsetupIdentityMiddleware()— not publicly accessible