feat: 站点提交/返回统一支持多名称多地址数组
- POST /sites/{id}/submit: names[]/urls[] 数组,兼容旧 name/baseUrl 单值
- 已有站点合并新名称/地址(去重+前置)
- 站点列表返回 names[]/urls[]
- API 文档和代码示例同步更新
This commit is contained in:
27
docs/API.md
27
docs/API.md
@@ -164,13 +164,14 @@ curl -H "If-None-Match: a1b2c3d4..." http://par:9012/api/v1/manifest
|
||||
#### POST /api/v1/sites/{siteId}/submit
|
||||
|
||||
```json
|
||||
// Request
|
||||
// Request (多名称/多地址)
|
||||
{
|
||||
"name": "PThome", // 必填
|
||||
"baseUrl": "https://pthome.net", // 必填
|
||||
"names": ["PThome", "PThome镜像"], // 必填
|
||||
"urls": ["https://pthome.net", "https://pthome.mirror"], // 必填
|
||||
// 或向后兼容单值: "name": "PThome", "baseUrl": "https://..."
|
||||
"description": "PT 资源站",
|
||||
"iconUrl": "https://...",
|
||||
"siteType": "private" // private/public
|
||||
"siteType": "private"
|
||||
}
|
||||
|
||||
// Response 200
|
||||
@@ -179,8 +180,8 @@ curl -H "If-None-Match: a1b2c3d4..." http://par:9012/api/v1/manifest
|
||||
"data": {
|
||||
"id": 1,
|
||||
"siteId": "pthome",
|
||||
"name": "PThome",
|
||||
"baseUrl": "https://pthome.net",
|
||||
"names": ["PThome", "PThome镜像"],
|
||||
"urls": ["https://pthome.net", "https://pthome.mirror"],
|
||||
"siteType": "private",
|
||||
"schemaVersion": "1.0.0",
|
||||
"status": "active",
|
||||
@@ -282,9 +283,9 @@ curl -H "If-None-Match: a1b2c3d4..." http://par:9012/api/v1/manifest
|
||||
|------|------|------|
|
||||
| id | Long | 内部 ID |
|
||||
| siteId | String | 站点唯一标识(如 `pthome`) |
|
||||
| name | String | 显示名称 |
|
||||
| names | String[] | 站点名称列表 |
|
||||
| urls | String[] | 站点地址列表 |
|
||||
| description | String | 描述 |
|
||||
| baseUrl | String | 站点 URL |
|
||||
| iconUrl | String | 图标 URL |
|
||||
| siteType | String | `private` / `public` |
|
||||
| schemaVersion | String | 当前 Schema 版本 |
|
||||
@@ -372,10 +373,10 @@ def hmac_headers(method, path):
|
||||
"X-Email": EMAIL
|
||||
}
|
||||
|
||||
def submit_site(site_id, name, base_url, site_type="private"):
|
||||
def submit_site(site_id, names, urls, site_type="private"):
|
||||
path = f"/api/v1/sites/{site_id}/submit"
|
||||
return requests.post(f"{BASE}{path}",
|
||||
json={"name": name, "baseUrl": base_url, "siteType": site_type},
|
||||
json={"names": names, "urls": urls, "siteType": site_type},
|
||||
headers=hmac_headers("POST", path)
|
||||
).json()
|
||||
|
||||
@@ -396,7 +397,7 @@ def download_config(site_id, version):
|
||||
return resp.json()
|
||||
|
||||
# ---- 使用 ----
|
||||
submit_site("pthome", "PThome", "https://pthome.net")
|
||||
submit_site("pthome", ["PThome", "PThome镜像"], ["https://pthome.net", "https://pthome.mirror"])
|
||||
submit_config("pthome", "1.0.0", '{"rules":[...]}')
|
||||
print(list_configs("pthome"))
|
||||
```
|
||||
@@ -429,12 +430,12 @@ async function hmacHeaders(method, path) {
|
||||
};
|
||||
}
|
||||
|
||||
async function submitSite(siteId, name, baseUrl, siteType = 'private') {
|
||||
async function submitSite(siteId, names, urls, siteType = 'private') {
|
||||
const path = `/api/v1/sites/${siteId}/submit`;
|
||||
const res = await fetch(`${BASE}${path}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...await hmacHeaders('POST', path) },
|
||||
body: JSON.stringify({ name, baseUrl, siteType })
|
||||
body: JSON.stringify({ names, urls, siteType })
|
||||
});
|
||||
return res.json();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user