mirror of
https://github.com/shy3130/tick-stock-panel.git
synced 2026-11-02 10:26:13 +00:00
feat(data-sources): 支持外部插件安装与版本管理
Signed-off-by: shy3130 <shy3130@qq.com>
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
"""Replace this URL and field mapping with your provider's documented contract."""
|
||||
import httpx
|
||||
|
||||
BASE_URL = "https://example.invalid"
|
||||
|
||||
|
||||
def fetch(key: str) -> list[dict]:
|
||||
if BASE_URL.endswith(".invalid"):
|
||||
raise ValueError("请先修改模板的接口地址")
|
||||
with httpx.Client(timeout=15) as client:
|
||||
response = client.get(f"{BASE_URL}/quotes", headers={"Authorization": f"Bearer {key}"})
|
||||
response.raise_for_status()
|
||||
return response.json()["data"]
|
||||
@@ -0,0 +1,13 @@
|
||||
name: example_http
|
||||
version: 1.0.0
|
||||
plugin_api_version: 1
|
||||
display_name: HTTP 数据源模板
|
||||
author: 插件开发者
|
||||
runtime: none
|
||||
entry: provider:Provider
|
||||
requires_app: '>=0.3.24'
|
||||
requires_python: '>=3.11'
|
||||
platforms: [any]
|
||||
datasets: [realtime]
|
||||
api_key_env: EXAMPLE_HTTP_API_KEY
|
||||
description: 开发模板,请先在 client.py 配置真实接口并完成字段转换和测试。
|
||||
@@ -0,0 +1,32 @@
|
||||
"""Example only: vendor data must already match the documented normalized schema."""
|
||||
from types import SimpleNamespace
|
||||
|
||||
from app import secrets_store
|
||||
from app.data_providers.base import ProviderRequestError
|
||||
|
||||
from .client import fetch
|
||||
|
||||
|
||||
def probe_api_key(key):
|
||||
try:
|
||||
fetch(key)
|
||||
return True, "接口可连接;其他能力权限需另行验证"
|
||||
except Exception: # noqa: BLE001 — never return raw HTTP errors containing credentials
|
||||
return False, "验证失败,请检查接口地址、Key、权限与网络"
|
||||
|
||||
|
||||
class Provider:
|
||||
name = "example_http"
|
||||
|
||||
def __init__(self):
|
||||
self.config = SimpleNamespace(datasets={"realtime": {}})
|
||||
self.key = secrets_store.get_env_backed_secret("example_http_api_key", "EXAMPLE_HTTP_API_KEY")
|
||||
|
||||
def get_realtime(self):
|
||||
try:
|
||||
return fetch(self.key)
|
||||
except Exception as exc:
|
||||
raise ProviderRequestError("行情请求失败,请检查供应商服务") from exc
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
Reference in New Issue
Block a user