更新自动切换状态

为当前账号开启或关闭自动数据源切换。

PATCH/api/settings/fallback
认证
控制台会话 Cookie。
成功状态
200

请求参数

参数类型位置必填说明
OriginURIheader是当前站点的完整来源。
enabledbooleanbody是是否启用自动数据源切换。

请求示例

JavaScript 示例可在本站已登录的浏览器中运行。cURL 和 Python 示例读取你本机的 cookies.txt Cookie 文件。请将会话 Cookie 视为私密凭据。

cURL
curl -i -X PATCH 'https://social2api.com/api/settings/fallback' \
  --cookie ./cookies.txt \
  -H 'Content-Type: application/json' \
  -H 'Origin: https://social2api.com' \
  --data-binary '{
  "enabled": false
}'
Python
from urllib.error import HTTPError
from urllib.request import Request, HTTPCookieProcessor, build_opener
from http.cookiejar import MozillaCookieJar

request = Request(
    "https://social2api.com/api/settings/fallback",
    method="PATCH",
    headers={
        "Content-Type": "application/json",
        "Origin": "https://social2api.com",
    },
    data="{\"enabled\":false}".encode("utf-8"),
)
cookies = MozillaCookieJar("./cookies.txt")
cookies.load(ignore_discard=True)
send = build_opener(HTTPCookieProcessor(cookies)).open
try:
    with send(request) as response:
        print(response.status, response.read().decode("utf-8"))
except HTTPError as error:
    print(error.code, error.read().decode("utf-8"))
JavaScript
const response = await fetch("/api/settings/fallback", {
  method: "PATCH",
  credentials: "same-origin",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "enabled": false
  }),
});
console.log(response.status, await response.text());

响应

200 · 示例响应
{
  "enabled": false,
  "providers": [
    {
      "id": "tikhub",
      "label": "TikHub",
      "configured": false,
      "status": "missing_config",
      "tasks": [
        "rednote",
        "douyin",
        "channels"
      ],
      "cooldownUntil": null,
      "lastError": null
    },
    {
      "id": "dataxapi",
      "label": "DataXAPI",
      "configured": false,
      "status": "missing_config",
      "tasks": [
        "rednote",
        "douyin",
        "channels"
      ],
      "cooldownUntil": null,
      "lastError": null
    },
    {
      "id": "socialtoai",
      "label": "SocialToAI",
      "configured": false,
      "status": "missing_config",
      "tasks": [
        "rednote",
        "douyin",
        "channels"
      ],
      "cooldownUntil": null,
      "lastError": null
    }
  ],
  "events": []
}
错误示例
{
  "error": "请先登录。"
}
字段类型说明
enabledboolean该账号是否允许自动切换数据源。
providers[].idstring供应商 ID。
providers[].labelstring供应商显示名称。
providers[].configuredboolean当前部署是否配置该供应商。
providers[].statusmissing_config | unchecked | healthy | cooldown当前实例的供应商状态。
providers[].tasksstring[]该供应商在当前部署启用的任务 ID。
providers[].cooldownUntilISO 8601 date-time | null当前冷却结束时间。
providers[].lastErrorstring | null最近记录的供应商故障原因。
events[].idstring切换记录 ID。
events[].atISO 8601 date-time记录时间。
events[].taskstring触发切换的取数任务。
events[].fromstring来源供应商 ID。
events[].tostring目标供应商 ID。
events[].reasonstring触发切换的原因。

错误状态

HTTP原因与处理
400请求格式或字段无效。
403浏览器来源校验未通过。
401控制台会话缺失、过期或无效。
405请求方法不受支持。
503此部署未配置该控制台服务。

使用细节

  • 写请求须包含与站点完全相同的 Origin。
  • 默认依次尝试 TikHub、DataXAPI、SocialToAI,跳过未配置、冷却或不支持输入的供应商。关闭自动切换时只尝试第一个已配置且适用的供应商。
  • JSON 请求体最多 1,024 字节且只能包含 enabled。