fix: expose rust acceleration availability

This commit is contained in:
jxxghp
2026-05-25 23:48:09 +08:00
parent 8bd1288e7e
commit d4718bf9dc
3 changed files with 16 additions and 2 deletions

View File

@@ -515,6 +515,7 @@ async def get_env_setting(_: User = Depends(get_current_active_user_async)):
"AUTH_VERSION": SitesHelper().auth_version,
"INDEXER_VERSION": SitesHelper().indexer_version,
"FRONTEND_VERSION": SystemChain().get_frontend_version(),
"RUST_ACCEL_AVAILABLE": rust_accel.is_available(),
"RUST_ACCEL_ENABLED": rust_accel.is_enabled(),
}
)

View File

@@ -314,7 +314,7 @@ All endpoints are under the base URL `{MP_HOST}`. Path parameters are shown as `
| Method | Path | Description |
|--------|------|-------------|
| GET | `/api/v1/system/env` | Get system configuration |
| GET | `/api/v1/system/env` | Get system configuration, including runtime versions and Rust acceleration availability/enabled status |
| POST | `/api/v1/system/env` | Update system configuration. Body: JSON object |
| GET | `/api/v1/system/setting/{key}` | Get system setting |
| POST | `/api/v1/system/setting/{key}` | Update system setting |

View File

@@ -82,12 +82,25 @@ _stub_module(
)
_stub_module("app.utils.crypto", HashUtils=_Dummy)
_stub_module("app.utils.http", RequestUtils=_Dummy, AsyncRequestUtils=_Dummy)
_stub_module("version", APP_VERSION="test")
_stub_module("version", APP_VERSION="test", FRONTEND_VERSION="frontend-test")
from app.api.endpoints import system as system_endpoint
class NettestSecurityTest(unittest.TestCase):
def test_get_env_setting_reports_rust_available_and_enabled_separately(self):
"""
系统配置接口应分别返回 Rust 扩展可用性和当前实际启用状态。
"""
with patch.object(system_endpoint.rust_accel, "is_available", return_value=True), patch.object(
system_endpoint.rust_accel, "is_enabled", return_value=False
):
resp = asyncio.run(system_endpoint.get_env_setting(_="token"))
self.assertTrue(resp.success)
self.assertTrue(resp.data["RUST_ACCEL_AVAILABLE"])
self.assertFalse(resp.data["RUST_ACCEL_ENABLED"])
def test_fetch_image_allows_signed_private_url(self):
"""
服务端签名过的私网图片 URL 可以继续代理,保证前端封面显示。