feat: integrate CoreDoc documentation routes into web server
- Add 'fs' feature to tower-http for ServeDir support - Integrate docs_routes() into main router - Support three documentation endpoints: * /docs/legacy - Legacy WASM documentation system * /docs/api - API documentation * /docs/cli - CLI documentation - Add generic type parameter to docs_routes for AppState compatibility - Add INSTALLATION.md with auto-installation instructions Tested successfully: - Service running on port 11438 - All documentation endpoints accessible - API health check passing
This commit is contained in:
+215
@@ -0,0 +1,215 @@
|
|||||||
|
# MarkBase 自动安装说明
|
||||||
|
|
||||||
|
## 新安装特性(v0.2.0+)
|
||||||
|
|
||||||
|
MarkBase 现在支持**自动安装**,无需手动配置数据库和用户:
|
||||||
|
|
||||||
|
- **自动检测用户 home 目录**:默认使用当前用户的 home 目录作为数据存储根目录
|
||||||
|
- **自动初始化数据库**:首次运行时自动创建 SQLite 数据库和表结构
|
||||||
|
- **预设 demo 用户**:自动创建 `demo/demo123` 用户,安装后即可使用
|
||||||
|
- **动态路径配置**:所有路径相对于用户 home 自动调整
|
||||||
|
|
||||||
|
## 快速开始
|
||||||
|
|
||||||
|
### 1. 基本启动(使用当前用户 home)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
markbase-core web-start --port 11438
|
||||||
|
```
|
||||||
|
|
||||||
|
**默认行为**:
|
||||||
|
- 数据目录:`~/markbase/data/`
|
||||||
|
- 数据库:`~/markbase/data/auth.sqlite`
|
||||||
|
- Demo 用户 home:`~/markbase/data/demo/`
|
||||||
|
|
||||||
|
### 2. 指定自定义 home 目录
|
||||||
|
|
||||||
|
```bash
|
||||||
|
markbase-core web-start --home /path/to/custom/home --port 11438
|
||||||
|
```
|
||||||
|
|
||||||
|
**路径布局**:
|
||||||
|
```
|
||||||
|
/home/markbase/
|
||||||
|
├── data/
|
||||||
|
│ ├── auth.sqlite # 用户认证数据库
|
||||||
|
│ ├── demo/ # demo 用户数据目录
|
||||||
|
│ ├── users/ # 其他用户数据目录
|
||||||
|
│ ├── webdav_versions/ # WebDAV 版本控制
|
||||||
|
│ └── s3_keys.json # S3 访问密钥(可选)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Demo 用户信息
|
||||||
|
|
||||||
|
| 项目 | 值 |
|
||||||
|
|------|---|
|
||||||
|
| 用户名 | `demo` |
|
||||||
|
| 密码 | `demo123` |
|
||||||
|
| 权限 | `{"*": ["/"]}` (全局读写) |
|
||||||
|
| Home 目录 | `{HOME}/markbase/data/demo/` |
|
||||||
|
|
||||||
|
### 登录测试
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST http://localhost:11438/api/v2/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"username":"demo","password":"demo123"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"token": "uuid-token",
|
||||||
|
"expires_at": "2026-10-13T07:51:20Z",
|
||||||
|
"user_id": "demo",
|
||||||
|
"groups": [],
|
||||||
|
"permissions": "{\"*\": [\"/\"]}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 新安装流程
|
||||||
|
|
||||||
|
### macOS/Linux
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. 编译项目
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
# 2. 启动服务(自动初始化)
|
||||||
|
./target/release/markbase-core web-start
|
||||||
|
|
||||||
|
# 3. 测试服务
|
||||||
|
curl http://localhost:11438/api/v2/health
|
||||||
|
|
||||||
|
# 4. 使用 demo 用户登录
|
||||||
|
curl -X POST http://localhost:11438/api/v2/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"username":"demo","password":"demo123"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Docker 容器
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. 创建容器并挂载数据卷
|
||||||
|
docker run -d \
|
||||||
|
--name markbase \
|
||||||
|
-p 11438:11438 \
|
||||||
|
-v markbase_data:/root/markbase \
|
||||||
|
markbase:latest \
|
||||||
|
web-start
|
||||||
|
|
||||||
|
# 2. 进入容器测试
|
||||||
|
docker exec -it markbase bash
|
||||||
|
curl http://localhost:11438/api/v2/health
|
||||||
|
```
|
||||||
|
|
||||||
|
## 生产部署建议
|
||||||
|
|
||||||
|
### 1. 创建专用用户
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 创建 markbase 用户
|
||||||
|
sudo useradd -r -s /bin/false markbase
|
||||||
|
|
||||||
|
# 创建数据目录
|
||||||
|
sudo mkdir -p /var/lib/markbase
|
||||||
|
sudo chown markbase:markbase /var/lib/markbase
|
||||||
|
|
||||||
|
# 启动服务
|
||||||
|
sudo -u markbase markbase-core web-start --home /var/lib/markbase
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 修改 demo 密码
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 使用 bcrypt 生成新密码哈希
|
||||||
|
# 然后更新数据库
|
||||||
|
sqlite3 /var/lib/markbase/markbase/data/auth.sqlite \
|
||||||
|
"UPDATE sftpgo_users SET password_hash='NEW_HASH' WHERE username='demo'"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 创建新用户
|
||||||
|
|
||||||
|
```sql
|
||||||
|
-- 示例:创建 admin 用户
|
||||||
|
INSERT INTO sftpgo_users (username, password_hash, home_dir, permissions, status, uid, gid, created_at)
|
||||||
|
VALUES (
|
||||||
|
'admin',
|
||||||
|
'$2b$12$...', -- bcrypt hash
|
||||||
|
'/var/lib/markbase/markbase/data/admin',
|
||||||
|
'{"*": ["/"]}',
|
||||||
|
1,
|
||||||
|
501,
|
||||||
|
20,
|
||||||
|
strftime('%s', 'now')
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
## 环境变量
|
||||||
|
|
||||||
|
| 变量名 | 说明 | 默认值 |
|
||||||
|
|--------|------|--------|
|
||||||
|
| `MARKBASE_ENABLE_SFTPGO_SYNC` | 启用 SFTPGo 同步 | `false` |
|
||||||
|
| `MB_WEBDAV_PARENT` | WebDAV 父目录 | `{HOME}/markbase/data` |
|
||||||
|
|
||||||
|
## 目录结构
|
||||||
|
|
||||||
|
```
|
||||||
|
~/markbase/
|
||||||
|
├── data/
|
||||||
|
│ ├── auth.sqlite # 认证数据库
|
||||||
|
│ ├── demo/ # demo 用户数据
|
||||||
|
│ ├── users/ # 其他用户数据
|
||||||
|
│ │ └── {username}.sqlite # 用户文件数据库
|
||||||
|
│ ├── webdav_versions/ # WebDAV 版本控制
|
||||||
|
│ └── s3_keys.json # S3 密钥(可选)
|
||||||
|
└── config/
|
||||||
|
├── markbase.toml # 服务配置
|
||||||
|
└── s3.toml # S3 配置
|
||||||
|
```
|
||||||
|
|
||||||
|
## 常见问题
|
||||||
|
|
||||||
|
### Q: 如何查看当前数据目录?
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s http://localhost:11438/api/v2/health | jq .data_dir
|
||||||
|
```
|
||||||
|
|
||||||
|
### Q: 如何备份数据?
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 备份整个数据目录
|
||||||
|
tar -czf markbase_backup_$(date +%Y%m%d).tar.gz ~/markbase/
|
||||||
|
|
||||||
|
# 仅备份数据库
|
||||||
|
cp ~/markbase/data/auth.sqlite ~/markbase/data/auth.sqlite.backup
|
||||||
|
```
|
||||||
|
|
||||||
|
### Q: 如何迁移到新服务器?
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. 停止服务
|
||||||
|
pkill -f "markbase-core web-start"
|
||||||
|
|
||||||
|
# 2. 打包数据
|
||||||
|
tar -czf markbase_data.tar.gz ~/markbase/
|
||||||
|
|
||||||
|
# 3. 在新服务器解压
|
||||||
|
tar -xzf markbase_data.tar.gz -C ~/
|
||||||
|
|
||||||
|
# 4. 启动服务
|
||||||
|
markbase-core web-start
|
||||||
|
```
|
||||||
|
|
||||||
|
## 下一步
|
||||||
|
|
||||||
|
1. **配置 WebDAV**:编辑 `config/markbase.toml` 设置上传路径
|
||||||
|
2. **配置 S3**:创建 `config/s3.toml` 启用 S3 存储
|
||||||
|
3. **启用 SFTPGo 同步**:设置环境变量 `MARKBASE_ENABLE_SFTPGO_SYNC=1`
|
||||||
|
4. **创建更多用户**:通过 SQL 或 API 创建用户
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**版本**:v0.2.0
|
||||||
|
**更新日期**:2026-10-12
|
||||||
@@ -18,7 +18,6 @@ sevenz-rust = { version = "0.6.1", optional = true } # 7z格式 ⚠️库不
|
|||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
axum = { version = "0.7", features = ["macros"] }
|
axum = { version = "0.7", features = ["macros"] }
|
||||||
bcrypt = "0.16"
|
bcrypt = "0.16"
|
||||||
sysinfo = "0.32"
|
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
lazy_static = "1.5"
|
lazy_static = "1.5"
|
||||||
@@ -73,10 +72,9 @@ rusty-s3 = "0.10" # S3 API 签名(AWS Signature V4)
|
|||||||
ureq = "2.12" # 輕量同步 HTTP 客戶端
|
ureq = "2.12" # 輕量同步 HTTP 客戶端
|
||||||
reqwest = { version = "0.12", optional = true } # Async HTTP client for AsyncS3Vfs
|
reqwest = { version = "0.12", optional = true } # Async HTTP client for AsyncS3Vfs
|
||||||
rayon = "1.10" # Phase 4: 并行加密
|
rayon = "1.10" # Phase 4: 并行加密
|
||||||
tower-http = { version = "0.5", features = ["cors"] }
|
tower-http = { version = "0.5", features = ["cors", "fs"] }
|
||||||
url = "2" # URL 解析(rusty-s3 依賴)
|
url = "2" # URL 解析(rusty-s3 依賴)
|
||||||
xattr = "1.0" # Extended attributes support (AFP_AfpInfo, Time Machine)
|
xattr = "1.0" # Extended attributes support (AFP_AfpInfo, Time Machine)
|
||||||
dirs = "5.0" # User home directory detection
|
|
||||||
|
|
||||||
# === SMB/CIFS Client (Phase 1) ===
|
# === SMB/CIFS Client (Phase 1) ===
|
||||||
smb2 = { path = "../vendor/smb2" } # Pure-Rust SMB2/3 client library with pipelined I/O
|
smb2 = { path = "../vendor/smb2" } # Pure-Rust SMB2/3 client library with pipelined I/O
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
use axum::Router;
|
use axum::Router;
|
||||||
use tower_http::services::ServeDir;
|
use tower_http::services::ServeDir;
|
||||||
|
|
||||||
pub fn docs_routes() -> Router {
|
pub fn docs_routes<S>() -> Router<S>
|
||||||
|
where
|
||||||
|
S: Clone + Send + Sync + 'static,
|
||||||
|
{
|
||||||
Router::new()
|
Router::new()
|
||||||
// Legacy WASM documentation system
|
// Legacy WASM documentation system
|
||||||
.nest_service("/legacy", ServeDir::new("/Users/accusys/momentry_core/docs_v1.0/doc_wasm"))
|
.nest_service("/docs/legacy", ServeDir::new("/Users/accusys/momentry_core/docs_v1.0/doc_wasm"))
|
||||||
|
|
||||||
// New API documentation
|
// New API documentation
|
||||||
.nest_service("/api", ServeDir::new("/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE"))
|
.nest_service("/docs/api", ServeDir::new("/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE"))
|
||||||
|
|
||||||
// New CLI documentation
|
// New CLI documentation
|
||||||
.nest_service("/cli", ServeDir::new("/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE"))
|
.nest_service("/docs/cli", ServeDir::new("/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE"))
|
||||||
}
|
}
|
||||||
@@ -26,6 +26,7 @@ use crate::audio;
|
|||||||
use crate::auth::{AuthState, LoginRequest};
|
use crate::auth::{AuthState, LoginRequest};
|
||||||
use crate::provider::sqlite::SqliteProvider;
|
use crate::provider::sqlite::SqliteProvider;
|
||||||
use crate::render;
|
use crate::render;
|
||||||
|
use crate::api::docs::docs_routes;
|
||||||
use filetree::{self, FileTree};
|
use filetree::{self, FileTree};
|
||||||
use tower_http::cors::CorsLayer;
|
use tower_http::cors::CorsLayer;
|
||||||
|
|
||||||
@@ -279,6 +280,8 @@ pub async fn run(port: u16, file: Option<String>, home: PathBuf) -> anyhow::Resu
|
|||||||
.route("/body", get(body_handler))
|
.route("/body", get(body_handler))
|
||||||
.route("/status", get(status_handler))
|
.route("/status", get(status_handler))
|
||||||
.route("/labels", get(get_labels).post(post_labels))
|
.route("/labels", get(get_labels).post(post_labels))
|
||||||
|
// CoreDoc documentation system
|
||||||
|
.merge(docs_routes())
|
||||||
// Auth endpoints (public)
|
// Auth endpoints (public)
|
||||||
.route("/api/v2/auth/login", post(login_handler))
|
.route("/api/v2/auth/login", post(login_handler))
|
||||||
.route("/api/v2/auth/logout", post(logout_handler))
|
.route("/api/v2/auth/logout", post(logout_handler))
|
||||||
|
|||||||
Reference in New Issue
Block a user