接口参考

后台·运维

审计日志、告警、备份快照与元数据导出(仅管理员)

审计日志

GET
/api/admin/audit

分页,可按操作者、动作、目标与时间范围过滤;target 精确匹配。仅管理员。

Authorization

session
cookieimgyoung_session<token>

登录下发的会话 cookie;状态变更请求须另以 X-CSRF-Token 头回传会话绑定的 CSRF 令牌。

Query Parameters

page?integer

页码,从 1 起;缺省 1

Range1 <= value
page_size?integer

每页条数;缺省 20,上限 100

Range1 <= value <= 100
actor?string

操作者用户 id

action?string

动作标识,形如 channel.create

target?string

操作目标标识(图片短 ID、渠道 id、Token id 等),精确匹配

since?string

时间范围下界(闭),UTC 文本 YYYY-MM-DD HH:MM:SS

until?string

时间范围上界(开),UTC 文本 YYYY-MM-DD HH:MM:SS

Response Body

审计分页

application/json
  1. response
items*array<>
total*integer
Formatint64
curl -X GET 'http://localhost:8721/api/admin/audit'
{  "items": [    {      "id": 0,      "actor": "string",      "actor_name": "string",      "action": "string",      "target": "string",      "detail": "string",      "created_at": "string"    }  ],  "total": 0}

告警

GET
/api/admin/alerts

缺省返回全部未恢复的告警(不分页);status=all 时分页返回全部历史,最新在前。仅管理员。

Authorization

session
cookieimgyoung_session<token>

登录下发的会话 cookie;状态变更请求须另以 X-CSRF-Token 头回传会话绑定的 CSRF 令牌。

Query Parameters

status?"all"

为 all 时含已恢复的历史

Value in"all"
page?integer

页码,从 1 起;缺省 1

Range1 <= value
page_size?integer

每页条数;缺省 20,上限 100

Range1 <= value <= 100

Response Body

告警列表

application/json
  1. response
items*array<>
total*integer
Formatint64
curl -X GET 'http://localhost:8721/api/admin/alerts'
{  "items": [    {      "id": 0,      "kind": "channel_unhealthy",      "target": "string",      "message": "string",      "opened_at": "string",      "resolved_at": "string"    }  ],  "total": 0}

备份快照列表

GET
/api/admin/backups

各健康渠道(不含清理中的渠道)上元数据库快照的并集,最新在前;每份快照列出持有它的渠道。仅管理员。

Authorization

session
cookieimgyoung_session<token>

登录下发的会话 cookie;状态变更请求须另以 X-CSRF-Token 头回传会话绑定的 CSRF 令牌。

Response Body

快照列表

application/json
  1. response
items*array<>
total*integer
Formatint64
curl -X GET 'http://localhost:8721/api/admin/backups'
{  "items": [    {      "name": "string",      "size": 0,      "taken_at": "2019-08-24T14:15:22Z",      "channels": [        "string"      ]    }  ],  "total": 0}

立即备份

POST
/api/admin/backups

立即做一次元数据库快照,同一份快照写到每个健康渠道(不含清理中的渠道),各渠道各自按保留份数清理旧快照。仅管理员。

Authorization

session
cookieimgyoung_session<token>

登录下发的会话 cookie;状态变更请求须另以 X-CSRF-Token 头回传会话绑定的 CSRF 令牌。

Header Parameters

X-CSRF-Token*string

登录或 GET /api/admin/me 响应里的 csrf_token;缺失或不匹配返回 403

Response Body

新快照,已写到每个健康渠道

application/json
  1. response

一份元数据库快照及持有它的渠道

name*string

对象文件名,形如 imgyoung-20060102-150405.000.db

size*integer

字节数

Formatint64
taken_at*string

快照时刻,RFC 3339,毫秒精度

Formatdate-time
channels*array<string>

持有该快照的健康渠道名,按优先级降序;立即备份的响应里即写入的全部渠道

curl -X POST 'http://localhost:8721/api/admin/backups' \  -H 'X-CSRF-Token: string'
{  "name": "string",  "size": 0,  "taken_at": "2019-08-24T14:15:22Z",  "channels": [    "string"  ]}

下载快照

GET
/api/admin/backups/{name}

以附件形式输出 SQLite 快照文件;按优先级从持有该快照的健康渠道读取,读取失败的渠道换下一个,各健康渠道都没有该快照时 404。仅管理员。

Authorization

session
cookieimgyoung_session<token>

登录下发的会话 cookie;状态变更请求须另以 X-CSRF-Token 头回传会话绑定的 CSRF 令牌。

Path Parameters

name*string

快照名,形如 imgyoung-20060102-150405.000.db

Response Body

快照文件

response?stringapplication/vnd.sqlite3
curl -X GET 'http://localhost:8721/api/admin/backups/string'
"string"

从快照恢复

POST
/api/admin/backups/{name}/restore

按优先级从持有该快照的健康渠道取回(读取失败的渠道换下一个,各健康渠道都没有该快照时 404),暂存到数据目录后触发优雅停机,进程被拉起时换入,原库改名保留;没有进程管理器拉起时,暂存文件等到下次启动再换入。仅管理员。

Authorization

session
cookieimgyoung_session<token>

登录下发的会话 cookie;状态变更请求须另以 X-CSRF-Token 头回传会话绑定的 CSRF 令牌。

Path Parameters

name*string

快照名,形如 imgyoung-20060102-150405.000.db

Header Parameters

X-CSRF-Token*string

登录或 GET /api/admin/me 响应里的 csrf_token;缺失或不匹配返回 403

Response Body

已暂存,服务即将停机

application/json
  1. response
snapshot*string

快照名

staged*string

暂存文件路径

message*string

服务端说明

curl -X POST 'http://localhost:8721/api/admin/backups/string/restore' \  -H 'X-CSRF-Token: string'
{  "snapshot": "string",  "staged": "string",  "message": "string"}

导出全部元数据

GET
/api/admin/export

图在哪些渠道、对象键与哈希全部在内,渠道带 id 与 created_at(加密渠道的密钥派生输入),渠道凭证与密码哈希不在内;以附件形式输出。仅管理员。

Authorization

session
cookieimgyoung_session<token>

登录下发的会话 cookie;状态变更请求须另以 X-CSRF-Token 头回传会话绑定的 CSRF 令牌。

Response Body

元数据全量

application/json
  1. response

元数据全量导出;渠道凭证与密码哈希不在内

users*array<>
channels*array<>
tokens*array<>
images*array<>
blobs*array<>
blob_channels*array<>
curl -X GET 'http://localhost:8721/api/admin/export'
{  "users": [    {      "id": "string",      "name": "string",      "role": "admin",      "quota_bytes": 0,      "default_ttl_hours": 0,      "disabled": true,      "created_at": "string",      "used_bytes": 0,      "image_count": 0    }  ],  "channels": [    {      "id": 0,      "name": "string",      "driver": "string",      "priority": 0,      "healthy": true,      "encrypted": true,      "allow_direct_link": true,      "last_checked_at": "string",      "last_error": "string",      "deleting": true,      "replicas": {        "done": 0,        "pending": 0,        "failed": 0      },      "created_at": "string"    }  ],  "tokens": [    {      "id": 0,      "user_id": "string",      "name": "string",      "prefix": "string",      "scopes": "string",      "revoked_at": "string",      "created_at": "string"    }  ],  "images": [    {      "id": "string",      "blob_id": 0,      "user_id": "string",      "token_id": 0,      "file_name": "string",      "object_key": "string",      "expire_at": "string",      "ttl_seconds": 0,      "last_public_access_at": "string",      "access_count": 0,      "pending_cleanup": true,      "cleanup_exempt": true,      "created_at": "string"    }  ],  "blobs": [    {      "id": 0,      "sha256": "string",      "phash": "string",      "storage_key": "string",      "mime": "string",      "size": 0,      "width": 0,      "height": 0,      "ref_count": 0,      "pending_delete": true,      "delete_after": "string",      "created_at": "string"    }  ],  "blob_channels": [    {      "blob_id": 0,      "channel_id": 0,      "state": "pending",      "attempts": 0,      "last_error": "string",      "updated_at": "string"    }  ]}