Alive API 文档

个人在线状态服务 · FastAPI · POST 安全写入

先记住这两条

查询数据使用 GET;修改数据使用 POST。 密钥不要放在 URL,推荐放在 Authorization: Bearer 你的密钥 请求头。

网页管理后台不需要手写 API。访问 /panel,输入密钥登录后即可直接修改状态、设备和隐私模式。

公开读取接口

方法路径作用需要密钥
GET/api/meta站点信息和版本
GET/api/status/query当前状态和设备
GET/api/status/list手动状态列表
GET/api/status/eventsSSE 实时状态流
GET/api/health/query心率和今日步数
GET/api/music/query当前音乐和同步歌词
GET/api/metrics访问次数统计

数据修改接口

方法路径JSON 内容
POST/api/status/set{"status": 1}
POST/api/device/set新增或更新设备
POST/api/device/app-icon上传 Android 当前应用图标
POST/api/admin/settings修改主页、弹幕和音乐目录
POST/api/admin/secret安全轮换全局密钥
POST/api/device/remove{"id": "desktop"}
POST/api/device/clear{}
POST/api/device/private{"private": true}
POST/api/health/set更新心率和今日步数
POST/api/music/set更新当前播放状态
POST/api/music/track/check按 SHA-256 检查是否已上传
POST/api/music/track/upload流式上传当前歌曲二进制

Windows PowerShell 上报示例

$secret = "填入 .env 中的 ALIVE_SECRET"
$headers = @{ Authorization = "Bearer $secret" }
$body = @{
  id = "windows-test"
  show_name = "Windows 测试机"
  using = $true
  status = "PowerShell"
} | ConvertTo-Json

Invoke-RestMethod `
  -Method Post `
  -Uri "http://localhost:9010/api/device/set" `
  -Headers $headers `
  -ContentType "application/json" `
  -Body $body

Windows 客户端关闭行为

Ctrl+C 最可靠:脚本会先上报“未使用”,然后退出。

直接关闭 PowerShell 或 Windows Terminal 页面时,脚本也会监听关闭事件并尝试上报,但操作系统可能直接终止子进程,因此不能保证请求一定发完。

Alive 还有服务端兜底:客户端每 60 秒发送心跳;连续 150 秒没有任何上报,设备会自动变成“未使用”。可通过 status.device_timeout 调整。

密钥安全

Alive 只使用一个全局密钥,后台和所有设备客户端共同使用。最低 6 位,不需要为每台设备设置不同密码;正式部署仍建议使用更长的随机值。

不要使用 ?secret=xxx。查询字符串可能进入浏览器历史、代理日志、服务器日志和监控系统,Alive 会拒绝这种认证方式。

推荐 Bearer 请求头。网页后台登录成功后使用签名的 HttpOnly Cookie,Cookie 中不包含原始密钥。

Alive API Documentation

Personal status service · FastAPI · Secure POST mutations

Two rules to remember

Use GET to read data and POST to change it. Never put the secret in a URL. Prefer the Authorization: Bearer YOUR_SECRET header.

You can manage everything in a browser at /panel without writing API requests.

Public read endpoints

MethodPathPurposeSecret
GET/api/metaSite metadata and versionNo
GET/api/status/queryCurrent status and devicesNo
GET/api/status/listManual status choicesNo
GET/api/status/eventsLive SSE status streamNo
GET/api/health/queryHeart rate and today's stepsNo
GET/api/music/queryCurrent music and timed lyricsNo
GET/api/metricsVisit metricsNo

Mutation endpoints

MethodPathJSON body
POST/api/status/set{"status": 1}
POST/api/device/setCreate or update a device
POST/api/device/app-iconUpload the current Android app icon
POST/api/admin/settingsUpdate homepage, danmaku, and music directory
POST/api/admin/secretSecurely rotate the global secret
POST/api/device/remove{"id": "desktop"}
POST/api/device/clear{}
POST/api/device/private{"private": true}
POST/api/health/setUpdate heart rate and steps
POST/api/music/setUpdate now-playing state
POST/api/music/track/checkCheck by SHA-256 before upload
POST/api/music/track/uploadStream the current audio file

Device update JSON

{
  "id": "windows-test",
  "show_name": "Windows PC",
  "using": true,
  "status": "PowerShell",
  "fields": {}
}

Closing the Windows client

Ctrl+C is the most reliable exit: the client reports “not using” before it stops.

Closing a PowerShell or Windows Terminal tab also triggers a best-effort close handler, but the operating system may kill the child process before the HTTP request finishes.

Server fallback: the client sends a heartbeat every 60 seconds. After 150 seconds without an update, Alive automatically marks the device as not using. Configure this with status.device_timeout.

Secret safety

Alive uses one global secret shared by the admin panel and all device clients. The minimum length is 6 characters; devices do not have separate passwords. Use a longer random value in production.

Do not use ?secret=xxx. Query strings can be recorded in browser history, proxy logs, server logs, and monitoring systems. Alive rejects query-string authentication.

Prefer a Bearer header. Browser admin sessions use a signed HttpOnly cookie that does not contain the original secret.