# alist 的api

post /api/auth/login 获取token

请求参数

| 名称     | 位置  | 类型   | 必选 | 说明   |
| -------- | ----- | ------ | ---- | ------ |
| Password | query | string | 是   | 密码   |
| Username | query | string | 是   | 用户名 |

返回值

成功

```json
{
  "code": 200,
  "message": "success",
  "data": {
    "token": "abcd"
  }
}
```

获取挂载的网盘列表

get api/fs/list

### 请求参数

| 名称          | 位置   | 类型    | 必选 | 说明       |
| ------------- | ------ | ------- | ---- | ---------- |
| Authorization | header | string  | 是   | 用户token  |
| Content-Type  | header | string  | 否   | none       |
| body          | body   | object  | 否   | none       |
| » page        | body   | integer | 否   | 当前页数   |
| » password    | body   | string  | 否   | 密码       |
| » path        | body   | string  | 否   | 路径       |
| » per_page    | body   | integer | 否   | 每页文件数 |
| » refresh     | body   | boolean | 否   | 强制刷新   |

### 返回结果

| 状态码 | 状态码含义 | 说明 | 数据模型 |
| ------ | ---------- | ---- | -------- |
| 200    | OK         | 成功 | Inline   |

创建文件夹

post /api/fs/mkdir

请求参数

| 名称          | 位置   | 类型   | 必选 | 说明       |
| ------------- | ------ | ------ | ---- | ---------- |
| Authorization | header | string | 是   | token      |
| Content-Type  | header | string | 否   | none       |
| body          | body   | object | 否   | none       |
| » path        | body   | string | 是   | 新目录路径 |

返回结果

| 状态码 | 状态码含义 | 说明 | 数据模型 |
| ------ | ---------- | ---- | -------- |
| 200    | OK         | 成功 | Inline   |

上传文件

put /api/fs/form

> Body 请求参数

```yaml
file: file://C:\test.jpg
```

请求参数

| 名称           | 位置   | 类型           | 必选 | 说明                       |
| -------------- | ------ | -------------- | ---- | -------------------------- |
| Authorization  | header | string         | 是   | token                      |
| Content-Type   | header | string         | 是   | 需要是multipart/form-data; |
| Content-Length | header | string         | 是   | 文件大小                   |
| file-path      | header | string         | 是   | 经过URL编码的完整文件路径  |
| body           | body   | object         | 否   | none                       |
| » file         | body   | string(binary) | 是   | 文件                       |

> 返回示例
> 成功

```json
{
  "code": 200,
  "message": "success",
  "data": null
}
```

返回结果

| 状态码 | 状态码含义 | 说明 | 数据模型 |
| ------ | ---------- | ---- | -------- |
| 200    | OK         | 成功 | Inline   |



## 示例

```
import requests
#登录
url = 'http://127.0.0.1:5244/api/auth/login' 
d = {'Username': 'admin', 'Password': 'admin'} 
r = requests.post(url, data=d) 
#print(r.text)


import json 
# 对登录后返回的数据进行解析
data = json.loads(r.text)
print('data',data.get('data').get('token'))

token = data.get('data').get('token')
# 查看网盘的列表
url2 = "http://127.0.0.1:5244/api/fs/list"

#r = requests.get(url2)

headers = {
   'Authorization': token
}
r = requests.get(url2,headers=headers)
print(r.text)

# 创建文件夹
url2 = "http://127.0.0.1:5244/api/fs/mkdir"
headers = {
   'Authorization':token
}

data = {
  'path': '/tianyi/test3'
}

res = requests.post(url=url2,data=data,headers=headers)
print(res.text)

# 上传文件
url2 = "http://127.0.0.1:5244/api/fs/form"

filename = '/root/python/1.txt'  #需要上传的文件

data = MultipartEncoder(
    fields={
        'file': (filename, open(filename, 'rb'))
    }
)

filename_new = quote(filename,'utf-8')  #对文件名进行URL编码
print('filename_new',filename_new)
headers = {
   'Authorization':token,
   'Content-Type': data.content_type,
   'file-path':'/tianyi/test3/'+filename_new   
}
print('header',headers.get('file-path'))
res = requests.put(url=url2,data=data,headers=headers)
print(res.text)


```

 参考文档

https://zhuanlan.zhihu.com/p/587004798