task-svr/docs/api.md
2024-01-02 16:36:52 +08:00

240 lines
4.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Task相关接口
### 说明
1. 通用返回格式, errcode=0 表示无错误
2. 如无特别说明, 以下接口的 Response 格式指的是 data 字段
3. 接口名中带\*的表示, 需要验证 token, token 可以设置 header 的 Authorization: Bearer JWT_token, 或 Post body 的 token 字段, 或 Get 的 query token
```json
{
"errcode": Number,
"errmsg": String,
"data": {}
}
```
### 1. 钱包预登录
#### Request
- URL`/api/wallet/nonce?address=`
- 方法:`GET`
query param
| Name | Type | Desc |
| ------- | ------ | -------- |
| address | string | 钱包地址 |
#### Response
```json
{
"nonce": String,
"tips": String
}
```
### 2. 钱包登录
客户端在获得钱包地址后,须先调用预登录方法获取 nonce 和 tips, 然后调用钱包进行 EIP-721 签名.
登录成功后返回的 jwt 需要保存至本地存储, 再次载入后, 可解析并获取 exp 字段, 判断当前 token 是否已经过期
#### Request
- URL`/api/wallet/login`
- 方法:`POST`
- 头部:
- Content-type: application/json
- Body:
```json
{
"activity": String,
"signature": String,
"message": SiweMessage
}
```
SiweMessage说明: https://docs.login.xyz/sign-in-with-ethereum/quickstart-guide/creating-siwe-messages
#### Response
```json
{
"token": String,
}
```
### 3. 活动信息
#### Request
- URL`/api/activity/:id`
- 方法:`GET`
- 参数:
- `id`当前活动的ID
#### Response
```js
{
"_id": "TwitterConnect", // 任务id
"name": "活动名称",
"description": "活动描述",
"tasks": [ // 该活动需要完成的任务
{
"id": "任务id",
"title": "任务名",
"desc": "任务描述"
}
],
"startTime": 1702628292366, // 活动开始时间
"endTime": 1705220292366 // 活动结束时间
}
```
### 4. *用户任务进度
#### Request
- URL`/api/tasks/progress`
- 方法:`POST`
- 头部:
- Authorization: Bearer JWT_token
- Body: {}
#### Response
```js
[
{
"status": 2, // 任务状态, 0: 未开始, 1: 进行中, 2: 成功, 9: 失败
"id": "TwitterConnect", // 任务id
"timeStart": 1703150269527, // 任务开始时间
"data": { // 当前任务带的额外信息, 比如twitter的id和昵称等
"username": "zhl01",
"userid": "564269223"
},
"timeFinish": 1703150280059 // 任务结束时间
}
]
```
### 5.\* 开始某个任务
#### Request
- URL`/api/tasks/begin_task`
- 方法:`POST`
- 头部:
- Authorization: Bearer JWT_token
body:
```js
{
"task": "TwitterFollow" // 任务id
}
```
#### Response
```json
{
"status": 1, // 任务状态, 0: 未开始, 1: 进行中, 2: 成功, 9: 失败
"id": "TwitterFollow", // 任务id
"timeStart": 1703150294051 // 任务开始时间
}
```
### 6.\* 检查任务状态
#### Request
- URL`/api/tasks/check_task`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
body:
```js
{
"task": "TwitterFollow" // 任务id
}
```
#### Response
```json
{
"status": 1, // 任务状态, 0: 未开始, 1: 进行中, 2: 成功, 9: 失败
"id": "TwitterFollow", // 任务id
"timeStart": 1703150294051, // 任务开始时间
"timeFinish": 1703151338598
}
```
### 6.\* 提交邀请码
#### Request
- URL`/api/activity/upload_invite_code`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
body:
```js
{
"code": "邀请人的邀请码"
}
```
#### Response
> 只要不返回errcode, 即表示上传成功
```json
{}
```
### 7. 积分排行榜
#### Request
- URL`/api/activity/leaderboard/:activity/:page`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
- 参数:
- `activity`当前活动的ID
- `page` (返回数据的分页序号, 0 开始)
> 默认返回50条记录, 如果要返回不同数量, query param传 limit
#### Response
```json
[
{
"rank": 1, // 排名
"address": "钱包地址",
"score": 获得的积分
}
]
```