Skip to content

Commit

Permalink
add /get/status_list
Browse files Browse the repository at this point in the history
  • Loading branch information
wyf9 committed Jul 31, 2024
1 parent 04b6eca commit 9a73201
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ python3 start.py
| -------------------------------------- | ------------------- |
| `/` | 显示主页 |
| `/query` | 获取状态 |
| `/get/status_list` | 获取可用状态列表 |
| `/set?secret=<secret>&status=<status>` | 设置状态 (url 参数) |
| `/set/<secret>/<status>` | 设置状态 (路径) |

> 以下是三个接口的解释
> 以下是 4 个接口的解释
1. `/query`:

Expand All @@ -95,7 +96,33 @@ python3 start.py
}
```

2. `/set?secret=<secret>&status=<status>`
2. `/get/status_list`

获取可用状态的列表 (无需鉴权)

返回 json:

```jsonc
[
{
"id": 0, // 索引,取决于配置文件中的有无
"name": "活着", // 状态名称
"desc": "目前在线,可以通过任何可用的联系方式联系本人。", // 状态描述
"color": "awake" // 状态颜色, 对应 static/style.css 中的 .sleeping .awake 等类
},
{
"id": 1,
"name": "似了",
"desc": "睡似了或其他原因不在线,紧急情况请使用电话联系。",
"color": "sleeping"
},
// 以此类推
]
```

> 就是返回 `data.json` 中的 `status_list` 字段
3. `/set?secret=<secret>&status=<status>`

设置当前状态

Expand Down Expand Up @@ -127,7 +154,7 @@ python3 start.py
}
```

3. `/set/<secret>/<status>`
4. `/set/<secret>/<status>`

同上 `2.`, 唯一的不同是 url 格式

Expand Down
2 changes: 1 addition & 1 deletion example.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"status_list": [ // 状态列表, 索引从 0 开始, 对应上面的 status
{ // status: 0

"id": 0, // 没有任何作用,仅为方便查看
"id": 0, // 与索引相同,非必须,仅为方便查看 (建议加上)
"name": "活着", // 状态名称
"desc": "目前在线,可以通过任何可用的联系方式联系本人。", // 状态描述
"color": "awake" // 状态颜色, 对应 static/style.css 中的 .sleeping .awake 等类, 可自行前往修改
Expand Down
7 changes: 6 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,14 @@ def query():
}
return u.format_dict(ret)

@app.route('/get/status_list')
def get_status_list():
showip(request, '/get/status_list')
stlst = d.dget('status_list')
return u.format_dict(stlst)

@app.route('/set', methods=['GET', 'POST'])
def set():
def set_normal():
showip(request, '/set')
if request.method == "GET":
status = escape(request.args.get("status"))
Expand Down

0 comments on commit 9a73201

Please sign in to comment.