Files
blog-press/docs/Web-Backend/Others/AList.md
2025-12-18 10:13:00 +08:00

74 lines
1.9 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.

---
title: AList简介和使用
date: 2025-12-17
---
# 一、简介
  [AList](https://alistgo.com/zh/)是一个支持多种存储,支持网页浏览和 WebDAV 的文件列表程序,由 gin 和 Solidjs 驱动。
# 二、安装
## 2.1 Docker安装
```yml
services:
alist:
image: xhofe/alist:v3.41.0
container_name: alist
restart: unless-stopped
volumes:
- ./data:/opt/alist/data
- /srv:/srv
ports:
- "5244:5244"
environment:
- PUID=0
- PGID=0
```
  这里的srv为宿主机的系统服务数据目录添加该映射可以让Alist能够访问宿主机/srv目录下的本地文件。
# 三、挂载
## 3.1 挂载本地存储
  打开控制台,选择存储->添加->本地存储,设置挂载路径(自定义,如`/local`),选择根文件夹路径为`/srv`,点击添加。
  这样就可以将`/local`路径映射到宿主机的`/srv`目录了。
  可以在宿主机的`/srv`目录中添加文件查看AList的主页是否可以正确显示。
# 四、API
  在线调试地址:[Alist-Public](https://alist-public.apifox.cn/)
## 4.1 登录
```JavaScript
const username = ''
const password = ''
// 1. 登录获取token
const login = await axios.post(`${AListUrl}/api/auth/login`, {
username,
password
})
const token = login.data.data.token
```
## 4.2 上传文件
```JavaScript
const data = new FormData()
data.append('file', options.file)
const filePath = `${AListPath}/${options.file.name}`
await axios({
method: 'put',
url: `${AListUrl}/api/fs/form`,
headers: {
Authorization: token,
'File-Path': filePath
},
data
})
```
## 4.3 下载文件
  在AList的文件路径中加上前缀`/p/`。例如文件路径为`/local/Test/test.mp4`,则下载路径为`/p/local/Test/test.mp4`
::: tip
以上为相对路径使用时加上相应的ip和端口号。
:::