OpenList API 的 MoonBit 客户端:认证、用户、管理、文件系统、公开接口与分享六个子模块
Dependencies
moon add q2316367743/open-list///|
async fn main {
// 方式一:永久 token
let client = @open-list.create_open_list_client_with_token(
"https://openlist.example.com",
"YOUR_PERMANENT_TOKEN",
)
// 方式二:账号密码(第一次需要认证的请求前自动登录)
let client = @open-list.create_open_list_client(
@open-list.Settings::new("https://openlist.example.com"),
@open-list.Credentials::password("admin", "your-password"),
)
try {
let entries = client.fs().list("/")
println("共 \{entries.total} 项")
println(client.public().init_status().initialized)
} catch {
@open-list.OpenListError::Api(error) => println("业务错误 \{error.code}: \{error.message}")
error => println("请求失败:\{error.message()}")
}
}| 访问器 | 包 | 覆盖 |
|---|---|---|
| client.auth() | src/auth | 登录(明文 / 预哈希 / LDAP)、退出、两步验证 |
| client.user() | src/user | /api/me、改资料、自己的 SSH 公钥 |
| client.admin() | src/admin | 元信息、用户、存储、驱动、设置、索引 |
| client.fs() | src/fs | 列目录 / 读取、文件管理、上传(流式 / 分片)、归档、离线下载 |
| client.public() | src/public | 站点设置、离线下载工具、归档扩展名、初始化 |
| client.share() | src/share | 分享记录的增删改查与启停 |
| 成员 | 说明 |
|---|---|
| settings() | 连接设置(base_url 已去掉结尾 /) |
| token() / set_token(String?) / is_logged_in() | 共享认证状态 |
| request(method, path, query?, body?, headers?) | 直接调用任意 /api/...,返回信封里的 data |
| 编号 | 主题 |
|---|---|
| 00 | 架构与分层 |
| 01 | 认证 Authentication |
| 02 | 当前用户 User |
| 03 | 管理 Admin |
| 04 | 文件系统 File System |
| 05 | 公共 Public |
| 06 | 分享 Sharing |
| 07 | JSON 建模约定 |
| 08 | 未封装的端点与逃生通道 |
| 09 | 真机联调程序 |
moon check # 静态检查
moon test # 全部测试(不联网,注入 Mock 传输层)
moon fmt # 格式化
moon info # 更新 .mbti
moon run src/main # 真机联调程序(永久 token 模式,见 docs/09)pub struct OpenListClient {
// private fields
}async fn OpenListClient::request(self : OpenListClient, http_method : Method, path : String, query? : Json, body? : Json, headers? : Array[(String, String)]) -> Json raise OpenListErrorlet status = client.request(Method::Get, "/api/public/init_status")// 1. 永久 token(后台生成的,直接拿来用)
let client = create_open_list_client(
Settings::new("https://openlist.example.com"),
Credentials::token("..."),
)
// 2. 账号密码:第一次需要认证的请求前自动登录,换取限时 token
let client = create_open_list_client(
Settings::new("https://openlist.example.com"),
Credentials::password("admin", "secret"),
)
let files = client.fs().list("/")Install
Download zipOpenList API 的 MoonBit 客户端:认证、用户、管理、文件系统、公开接口与分享六个子模块
Dependencies