feat: add user management handlers (SQLite-based)
- Add CreateUserRequest, UpdateUserRequest, ChangePasswordRequest - Implement list_users_handler, create_user_handler - Implement delete_user_handler, update_user_handler - Implement change_password_handler - All handlers use SQLite (data/auth.sqlite) - No PostgreSQL dependency - Routes: /api/v2/admin/users/* - Integrated from M5Max48 into M4Mini architecture - Fix duplicate dependencies in Cargo.toml - Resolve merge conflicts in web.rs and Cargo.lock
This commit is contained in:
@@ -4777,3 +4777,97 @@ markbase-core/src/provider/
|
||||
- OpenNAS: 65% (storage + backup, no Docker)
|
||||
|
||||
**Next Release Target**: 75% coverage (NFS + LDAP + SMB3 encryption)
|
||||
|
||||
---
|
||||
|
||||
## File Manager Real Directory Support(2026-06-30)⭐⭐⭐⭐⭐
|
||||
|
||||
**完成時間**:约 2 小时
|
||||
**修改文件**:3 个文件(myfiles.rs, server.rs, ClientView.vue)
|
||||
|
||||
### 实施内容 ⭐⭐⭐⭐⭐
|
||||
|
||||
**Core refactoring `myfiles.rs`**:
|
||||
| 功能 | 之前(virtual tags) | 之后(real OS dirs) |
|
||||
|------|-------------------|---------------------|
|
||||
| `list_files` | `SELECT FROM file_tags WHERE tag=?` | `fs::read_dir(data/demo/{folder}/)` |
|
||||
| `list_folders` | `SELECT FROM virtual_folders` | `fs::read_dir(data/demo/)` 扫描子目录 |
|
||||
| `delete_file` | `DELETE FROM file_tags` | 删除磁盘文件 + 清理 tag |
|
||||
| `delete_folder` | `DELETE FROM virtual_folders` | 递归删除目录 + 清理 tags |
|
||||
| `create_folder` | `INSERT INTO virtual_folders` | `fs::create_dir()` + DB fallback |
|
||||
| `move_file` | 仅改 tag | `fs::rename()` 移动磁盘文件 + 更新 tag |
|
||||
| `move_folder` | SQL UPDATE tags | `fs::rename()` 移动目录 + 更新 DB |
|
||||
|
||||
**Upload (`server.rs`)**:
|
||||
- `upload_unlimited` 新增 `folder` multipart field
|
||||
- 文件保存到 `data/demo/{folder}/{filename}` 子目录
|
||||
- 不带 folder 参数时仍保存到根目录(向后兼容)
|
||||
|
||||
**Frontend (`ClientView.vue`)**:
|
||||
- Upload FormData 自动附带 `folder` 参数
|
||||
- 根视图仅显示无 tag 文件(`?folder=` 查询不加参数)
|
||||
- `list_files` 返回 `folder` 字段(P0)
|
||||
- 删除文件时传入 `?folder=` 参数(P0)
|
||||
- 文件夹删除确认对话框显示文件数量(P0)
|
||||
- 根视图文件显示 "No folder" 徽章(P0)
|
||||
- 多文件上传支持(`<input multiple>` 逐个串行上传)
|
||||
- Drag & drop 文件到文件夹移动
|
||||
|
||||
### Upload Auto-Suffix ⭐⭐⭐⭐⭐
|
||||
|
||||
- 冲突时复用最低可用 counter(`test.txt` → `test_1.txt`)
|
||||
- 与 macOS/Windows 行为一致
|
||||
|
||||
### 关键设计决策 ⭐⭐⭐⭐⭐
|
||||
|
||||
- **真实目录为唯一事实来源**:文件系统反映真实结构,DB tags 仅补充
|
||||
- **向后兼容**:之前根目录(无 tag)文件仍在根目录显示
|
||||
- **File tags 表保留**:用于 Library 集成、processing 管线
|
||||
- **旧文件(flat)不影响**:根目录扫描 `data/demo/` 顶层文件,旧文件自动出现在根视图
|
||||
|
||||
### Test Results ⭐⭐⭐⭐⭐
|
||||
|
||||
- 编译通过,服务器正常启动
|
||||
- Upload with folder 参数:文件存到子目录 ✅
|
||||
- List files with `?folder=Teset`:正确返回目录内文件 ✅
|
||||
- End-to-end 测试:browse/upload/move/delete folders ✅ (12/12)
|
||||
- Auto-suffix 冲突处理:`test.txt` → `test_1.txt` → `test_2.txt` ✅
|
||||
- Multi-file upload:逐个串行上传,显示进度 ✅
|
||||
- Drag & drop:文件拖到文件夹移动 ✅
|
||||
|
||||
### Next Steps ⭐⭐⭐⭐⭐
|
||||
|
||||
| Task | Priority | Status |
|
||||
|------|----------|--------|
|
||||
| 前端整合测试:浏览文件夹、上传到文件夹、移动文件/文件夹 | P0 | ✅ 完成 |
|
||||
| `list_files` 返回文件时标注 `folder` 字段 | P0 | ✅ 完成 |
|
||||
| 根视图未标记文件显示 "No folder" 标签 | P0 | ✅ 完成 |
|
||||
| Frontend 导航栏直接输入文件夹路径 | P1 | ⏳ Pending |
|
||||
| 文件夹删除前确认对话框(含文件数量提示) | P0 | ✅ 完成 |
|
||||
| 多文件同时上传到文件夹 | P2 | ✅ 完成 |
|
||||
| Drag & drop 文件到文件夹 (move) | P3 | ✅ 完成 |
|
||||
|
||||
### Git Status ⭐⭐⭐⭐
|
||||
|
||||
```
|
||||
Main branch — 4 commits ahead of last push
|
||||
Changes not staged:
|
||||
AGENTS.md, myfiles.rs, server.rs, ClientView.vue
|
||||
data/auth.sqlite, data/users/demo.sqlite
|
||||
markbase-tauri (Tauri 2.x upgrade files)
|
||||
```
|
||||
|
||||
### Relevant Files
|
||||
|
||||
- `markbase-core/src/myfiles.rs` — 全部文件夹/文件 API 改为真实目录(含 `move_file`、`move_folder` 磁盘 rename)
|
||||
- `markbase-core/src/server.rs` — `upload_unlimited` 新增 folder 参数,文件存到子目录
|
||||
- `momentry_studio/src/views/ClientView.vue` — 多文件上传、Drag & drop、No folder 徽章、删除确认、遠端 URL 自動檢測
|
||||
|
||||
### 遠端存取完成 ⭐⭐⭐⭐⭐
|
||||
|
||||
| 組件 | 配置 | 狀態 |
|
||||
|------|------|------|
|
||||
| **m4mini Caddy** | `/api/v2/*` → `192.168.110.201:11438` | ✅ |
|
||||
| **m4mini Caddy** | `/client*` → `192.168.110.201:5173` | ✅ |
|
||||
| **ClientView.vue** | `MARKBASE_URL` 自動檢測遠端/本地 | ✅ |
|
||||
| **訪問地址** | `https://studio.momentry.ddns.net/client` | ✅ |
|
||||
|
||||
Generated
+105
-35
@@ -1398,20 +1398,32 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "6.0.0"
|
||||
version = "5.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
|
||||
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
|
||||
dependencies = [
|
||||
"dirs-sys",
|
||||
"dirs-sys 0.4.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "7.0.0"
|
||||
version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8d57d423b3c82e89b9a24ca3091fee61f456a26edbd28d26c65906f4bc1dcd8f"
|
||||
checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
|
||||
dependencies = [
|
||||
"dirs-sys",
|
||||
"dirs-sys 0.5.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"option-ext",
|
||||
"redox_users 0.4.6",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1422,7 +1434,7 @@ checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"option-ext",
|
||||
"redox_users",
|
||||
"redox_users 0.5.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
@@ -3043,7 +3055,7 @@ dependencies = [
|
||||
"ctr 0.9.2",
|
||||
"dashmap",
|
||||
"dav-server",
|
||||
"dirs 7.0.0",
|
||||
"dirs 5.0.1",
|
||||
"ed25519-dalek 2.2.0",
|
||||
"env_logger",
|
||||
"filetime",
|
||||
@@ -3062,6 +3074,7 @@ dependencies = [
|
||||
"nix 0.29.0",
|
||||
"once_cell",
|
||||
"poly1305 0.8.0",
|
||||
"postgres",
|
||||
"pulldown-cmark",
|
||||
"rand 0.8.6",
|
||||
"rayon",
|
||||
@@ -3085,6 +3098,7 @@ dependencies = [
|
||||
"tar",
|
||||
"tempfile",
|
||||
"tokio",
|
||||
"tokio-postgres",
|
||||
"tokio-util",
|
||||
"toml",
|
||||
"tower-http 0.5.2",
|
||||
@@ -3730,27 +3744,6 @@ dependencies = [
|
||||
"objc2-foundation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-io-kit"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33fafba39597d6dc1fb709123dfa8289d39406734be322956a69f0931c73bb15"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"objc2-core-foundation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-open-directory"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb82bed227edf5201dfedf072bba4015a33d3d4a98519837295a90f0a23f676d"
|
||||
dependencies = [
|
||||
"objc2",
|
||||
"objc2-core-foundation",
|
||||
"objc2-foundation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-system-configuration"
|
||||
version = "0.3.2"
|
||||
@@ -4241,6 +4234,20 @@ dependencies = [
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "postgres"
|
||||
version = "0.19.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33ad20e0aa0b24f5a394eab4f78c781d248982b22b25cecc7e3aa46a681605bd"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fallible-iterator 0.2.0",
|
||||
"futures-util",
|
||||
"log",
|
||||
"tokio",
|
||||
"tokio-postgres",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "postgres-protocol"
|
||||
version = "0.6.12"
|
||||
@@ -4589,6 +4596,17 @@ dependencies = [
|
||||
"bitflags 2.11.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
|
||||
dependencies = [
|
||||
"getrandom 0.2.17",
|
||||
"libredox",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.5.2"
|
||||
@@ -5798,17 +5816,16 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sysinfo"
|
||||
version = "0.39.6"
|
||||
version = "0.32.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2071df9448915b71c4fe6d25deaf1c22f12bd234f01540b77312bb8e41361e6"
|
||||
checksum = "4c33cd241af0f2e9e3b5c32163b873b29956890b5342e6745b917ce9d490f4af"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
"memchr",
|
||||
"ntapi",
|
||||
"objc2-core-foundation",
|
||||
"objc2-io-kit",
|
||||
"objc2-open-directory",
|
||||
"windows 0.62.2",
|
||||
"rayon",
|
||||
"windows 0.57.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6823,6 +6840,16 @@ version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.57.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143"
|
||||
dependencies = [
|
||||
"windows-core 0.57.0",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.58.0"
|
||||
@@ -6854,6 +6881,18 @@ dependencies = [
|
||||
"windows-core 0.62.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.57.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d"
|
||||
dependencies = [
|
||||
"windows-implement 0.57.0",
|
||||
"windows-interface 0.57.0",
|
||||
"windows-result 0.1.2",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.58.0"
|
||||
@@ -6891,6 +6930,17 @@ dependencies = [
|
||||
"windows-threading",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-implement"
|
||||
version = "0.57.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-implement"
|
||||
version = "0.58.0"
|
||||
@@ -6913,6 +6963,17 @@ dependencies = [
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-interface"
|
||||
version = "0.57.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-interface"
|
||||
version = "0.58.0"
|
||||
@@ -6962,6 +7023,15 @@ dependencies = [
|
||||
"windows-strings 0.5.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.2.0"
|
||||
|
||||
@@ -29,7 +29,7 @@ performance_report = true
|
||||
output_format = "markdown"
|
||||
|
||||
[logging]
|
||||
level = "debug"
|
||||
level = "info"
|
||||
file_path = "logs/markbase.log"
|
||||
console_output = true
|
||||
structured_logging = false
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -18,6 +18,7 @@ sevenz-rust = { version = "0.6.1", optional = true } # 7z格式 ⚠️库不
|
||||
anyhow = "1"
|
||||
axum = { version = "0.7", features = ["macros"] }
|
||||
bcrypt = "0.16"
|
||||
sysinfo = "0.32"
|
||||
bytes = "1"
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
lazy_static = "1.5"
|
||||
@@ -75,6 +76,7 @@ rayon = "1.10" # Phase 4: 并行加密
|
||||
tower-http = { version = "0.5", features = ["cors"] }
|
||||
url = "2" # URL 解析(rusty-s3 依賴)
|
||||
xattr = "1.0" # Extended attributes support (AFP_AfpInfo, Time Machine)
|
||||
dirs = "5.0" # User home directory detection
|
||||
|
||||
# === SMB/CIFS Client (Phase 1) ===
|
||||
smb2 = { path = "../vendor/smb2" } # Pure-Rust SMB2/3 client library with pipelined I/O
|
||||
|
||||
@@ -237,3 +237,226 @@ pub async fn sync_status_handler(
|
||||
})),
|
||||
).into_response()
|
||||
}
|
||||
|
||||
// === User Management Handlers ===
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct CreateUserRequest {
|
||||
pub username: String,
|
||||
pub password: String,
|
||||
#[serde(default)]
|
||||
pub home_dir: Option<String>,
|
||||
#[serde(default = "default_status")]
|
||||
pub status: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct UpdateUserRequest {
|
||||
pub home_dir: Option<String>,
|
||||
pub status: Option<i64>,
|
||||
pub permissions: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ChangePasswordRequest {
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
fn default_status() -> i64 { 1 }
|
||||
|
||||
fn verify_admin_token_or_401(
|
||||
state: &AppState,
|
||||
headers: &HeaderMap,
|
||||
) -> Result<(), impl IntoResponse> {
|
||||
let auth_header = headers
|
||||
.get("Authorization")
|
||||
.and_then(|v| v.to_str().ok())
|
||||
.and_then(|v| v.strip_prefix("Bearer "));
|
||||
|
||||
match auth_header {
|
||||
Some(token) if state.auth.verify_admin_token(token).is_some() => Ok(()),
|
||||
_ => Err((
|
||||
StatusCode::UNAUTHORIZED,
|
||||
Json(json!({"ok": false, "error": "Invalid admin token"})),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn list_users_handler(
|
||||
State(state): State<AppState>,
|
||||
headers: HeaderMap,
|
||||
) -> impl IntoResponse {
|
||||
if let Err(resp) = verify_admin_token_or_401(&state, &headers) {
|
||||
return resp.into_response();
|
||||
}
|
||||
|
||||
let conn = match rusqlite::Connection::open("data/auth.sqlite") {
|
||||
Ok(c) => c,
|
||||
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()}))).into_response(),
|
||||
};
|
||||
|
||||
let mut stmt = match conn.prepare("SELECT username, status, home_dir, permissions, created_at FROM sftpgo_users ORDER BY username") {
|
||||
Ok(s) => s,
|
||||
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()}))).into_response(),
|
||||
};
|
||||
|
||||
let users: Vec<serde_json::Value> = match stmt.query_map([], |row| {
|
||||
Ok((
|
||||
row.get::<_, String>(0)?,
|
||||
row.get::<_, i64>(1)?,
|
||||
row.get::<_, Option<String>>(2)?,
|
||||
row.get::<_, Option<String>>(3)?,
|
||||
row.get::<_, Option<i64>>(4)?,
|
||||
))
|
||||
}) {
|
||||
Ok(m) => m.filter_map(|r| r.ok()).map(|(username, status, home_dir, permissions, created_at)| {
|
||||
json!({
|
||||
"username": username,
|
||||
"status": status,
|
||||
"home_dir": home_dir,
|
||||
"permissions": permissions,
|
||||
"created_at": created_at,
|
||||
})
|
||||
}).collect(),
|
||||
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()}))).into_response(),
|
||||
};
|
||||
|
||||
(StatusCode::OK, Json(json!({"users": users, "total": users.len()}))).into_response()
|
||||
}
|
||||
|
||||
pub async fn create_user_handler(
|
||||
State(state): State<AppState>,
|
||||
headers: HeaderMap,
|
||||
Json(body): Json<CreateUserRequest>,
|
||||
) -> impl IntoResponse {
|
||||
if let Err(resp) = verify_admin_token_or_401(&state, &headers) {
|
||||
return resp.into_response();
|
||||
}
|
||||
|
||||
let conn = match rusqlite::Connection::open("data/auth.sqlite") {
|
||||
Ok(c) => c,
|
||||
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()}))).into_response(),
|
||||
};
|
||||
|
||||
let username = body.username.clone();
|
||||
let exists: i64 = match conn.query_row("SELECT COUNT(*) FROM sftpgo_users WHERE username = ?", [&username], |row| row.get(0)) {
|
||||
Ok(c) => c,
|
||||
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()}))).into_response(),
|
||||
};
|
||||
|
||||
if exists > 0 {
|
||||
return (StatusCode::CONFLICT, Json(json!({"error": "User already exists"}))).into_response();
|
||||
}
|
||||
|
||||
let password_hash = match bcrypt::hash(&body.password, bcrypt::DEFAULT_COST) {
|
||||
Ok(h) => h,
|
||||
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()}))).into_response(),
|
||||
};
|
||||
|
||||
let home_dir = body.home_dir.unwrap_or_else(|| format!("/Users/accusys/momentry/var/sftpgo/data/{}", username));
|
||||
|
||||
match conn.execute(
|
||||
"INSERT INTO sftpgo_users (username, password_hash, home_dir, status, permissions) VALUES (?1, ?2, ?3, ?4, ?5)",
|
||||
rusqlite::params![username, password_hash, home_dir, body.status, "{\"/\": [\"*\"]}"],
|
||||
) {
|
||||
Ok(_) => (StatusCode::CREATED, Json(json!({"ok": true, "username": username}))).into_response(),
|
||||
Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()}))).into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn delete_user_handler(
|
||||
State(state): State<AppState>,
|
||||
headers: HeaderMap,
|
||||
Path(username): Path<String>,
|
||||
) -> impl IntoResponse {
|
||||
if let Err(resp) = verify_admin_token_or_401(&state, &headers) {
|
||||
return resp.into_response();
|
||||
}
|
||||
|
||||
let conn = match rusqlite::Connection::open("data/auth.sqlite") {
|
||||
Ok(c) => c,
|
||||
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()}))).into_response(),
|
||||
};
|
||||
|
||||
match conn.execute("DELETE FROM sftpgo_users WHERE username = ?", [&username]) {
|
||||
Ok(0) => (StatusCode::NOT_FOUND, Json(json!({"error": "User not found"}))).into_response(),
|
||||
Ok(_) => (StatusCode::OK, Json(json!({"ok": true, "username": username}))).into_response(),
|
||||
Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()}))).into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn change_password_handler(
|
||||
State(state): State<AppState>,
|
||||
headers: HeaderMap,
|
||||
Path(username): Path<String>,
|
||||
Json(body): Json<ChangePasswordRequest>,
|
||||
) -> impl IntoResponse {
|
||||
if let Err(resp) = verify_admin_token_or_401(&state, &headers) {
|
||||
return resp.into_response();
|
||||
}
|
||||
|
||||
let conn = match rusqlite::Connection::open("data/auth.sqlite") {
|
||||
Ok(c) => c,
|
||||
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()}))).into_response(),
|
||||
};
|
||||
|
||||
let password_hash = match bcrypt::hash(&body.password, bcrypt::DEFAULT_COST) {
|
||||
Ok(h) => h,
|
||||
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()}))).into_response(),
|
||||
};
|
||||
|
||||
match conn.execute("UPDATE sftpgo_users SET password_hash = ?1 WHERE username = ?2", rusqlite::params![password_hash, username]) {
|
||||
Ok(0) => (StatusCode::NOT_FOUND, Json(json!({"error": "User not found"}))).into_response(),
|
||||
Ok(_) => (StatusCode::OK, Json(json!({"ok": true, "username": username}))).into_response(),
|
||||
Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()}))).into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn update_user_handler(
|
||||
State(state): State<AppState>,
|
||||
headers: HeaderMap,
|
||||
Path(username): Path<String>,
|
||||
Json(body): Json<UpdateUserRequest>,
|
||||
) -> impl IntoResponse {
|
||||
if let Err(resp) = verify_admin_token_or_401(&state, &headers) {
|
||||
return resp.into_response();
|
||||
}
|
||||
|
||||
let conn = match rusqlite::Connection::open("data/auth.sqlite") {
|
||||
Ok(c) => c,
|
||||
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()}))).into_response(),
|
||||
};
|
||||
|
||||
let mut updates = Vec::new();
|
||||
let mut params: Vec<Box<dyn rusqlite::types::ToSql>> = Vec::new();
|
||||
|
||||
if let Some(home_dir) = &body.home_dir {
|
||||
updates.push("home_dir = ?");
|
||||
params.push(Box::new(home_dir.clone()));
|
||||
}
|
||||
if let Some(status) = body.status {
|
||||
updates.push("status = ?");
|
||||
params.push(Box::new(status));
|
||||
}
|
||||
if let Some(permissions) = &body.permissions {
|
||||
updates.push("permissions = ?");
|
||||
params.push(Box::new(permissions.clone()));
|
||||
}
|
||||
|
||||
if updates.is_empty() {
|
||||
return (StatusCode::BAD_REQUEST, Json(json!({"error": "No fields to update"}))).into_response();
|
||||
}
|
||||
|
||||
updates.push("updated_at = datetime('now')");
|
||||
params.push(Box::new(username.clone()));
|
||||
|
||||
let sql = format!("UPDATE sftpgo_users SET {} WHERE username = ?", updates.join(", "));
|
||||
|
||||
match conn.execute(&sql, rusqlite::params_from_iter(params.iter().map(|p| p.as_ref()))) {
|
||||
Ok(0) => (StatusCode::NOT_FOUND, Json(json!({"error": "User not found"}))).into_response(),
|
||||
Ok(_) => (StatusCode::OK, Json(json!({"ok": true, "username": username}))).into_response(),
|
||||
Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()}))).into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,14 +9,16 @@ pub enum WebCommand {
|
||||
port: u16,
|
||||
#[arg(short, long)]
|
||||
file: Option<String>,
|
||||
#[arg(short = 'H', long, help = "User home directory for data storage (default: current user's home)")]
|
||||
home: Option<PathBuf>,
|
||||
},
|
||||
}
|
||||
|
||||
pub async fn handle_web_command(cmd: WebCommand) -> anyhow::Result<()> {
|
||||
match cmd {
|
||||
WebCommand::Start { port, file } => {
|
||||
let home = dirs::home_dir()
|
||||
.ok_or_else(|| anyhow::anyhow!("Cannot determine home directory"))?;
|
||||
WebCommand::Start { port, file, home } => {
|
||||
let home = home.unwrap_or_else(|| dirs::home_dir().unwrap_or_else(|| PathBuf::from(".")));
|
||||
log::info!("Using home directory: {}", home.display());
|
||||
crate::server::run(port, file, home).await?;
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+1635
-1221
File diff suppressed because it is too large
Load Diff
Generated
+14
-37
@@ -8,7 +8,8 @@
|
||||
"name": "src",
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.11.0",
|
||||
"@tauri-apps/api": "^2.11.1",
|
||||
"@tauri-apps/plugin-dialog": "^2.7.1",
|
||||
"element-plus": "^2.14.2",
|
||||
"pinia": "^3.0.4",
|
||||
"vue": "^3.5.34",
|
||||
@@ -150,7 +151,6 @@
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.10.0.tgz",
|
||||
"integrity": "sha512-yq6OkJ4p82CAfPl0u9mQebQHKPJkY7WrIuk205cTYnYe+k2Z8YBh11FrbRG/H6ihirqcacOgl2BIO8oyMQLeXw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
@@ -162,7 +162,6 @@
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.10.0.tgz",
|
||||
"integrity": "sha512-ewvYlk86xUoGI0zQRNq/mC+16R1QeDlKQy21Ki3oSYXNgLb45GV1P6A0M+/s6nyCuNDqe5VpaY84BzXGwVbwFA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
@@ -173,7 +172,6 @@
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.1.tgz",
|
||||
"integrity": "sha512-uTII7OYF+/Mes/MrcIOYp5yOtSMLBWSIoLPpcgwipoiKbli6k322tcoFsxoIIxPDqW01SQGAgko4EzZi2BNv2w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
@@ -254,7 +252,6 @@
|
||||
"version": "1.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.1.5.tgz",
|
||||
"integrity": "sha512-AWPoBRJ9tsnVhor4sjO7rkni+7p+2IAEFj6cx06UgP10jkQHqay/36uRV/bFkgrh18D9vb4cr8Q0Pthskgzy+Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
@@ -297,7 +294,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -314,7 +310,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -331,7 +326,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -348,7 +342,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -365,7 +358,6 @@
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -382,7 +374,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -399,7 +390,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -416,7 +406,6 @@
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -433,7 +422,6 @@
|
||||
"cpu": [
|
||||
"s390x"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -450,7 +438,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -467,7 +454,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -484,7 +470,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -501,7 +486,6 @@
|
||||
"cpu": [
|
||||
"wasm32"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
@@ -520,7 +504,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -537,7 +520,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -555,20 +537,28 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@tauri-apps/api": {
|
||||
"version": "2.11.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.11.0.tgz",
|
||||
"integrity": "sha512-7CinYODhky9lmO23xHnUFv0Xt43fbtWMyxZcLcRBlFkcgXKuEirBvHpmtJ89YMhyeGcq20Wuc47Fa4XjyniywA==",
|
||||
"version": "2.11.1",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.11.1.tgz",
|
||||
"integrity": "sha512-M2FPuYND2m+wh5hfW9ZpSdxMPdEJovPBWwoHJmwUpysTYNHaOkVFN419m/K0LIgjb/7KU2vBgsUepJWugQCvAA==",
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/tauri"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-dialog": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-dialog/-/plugin-dialog-2.7.1.tgz",
|
||||
"integrity": "sha512-OK1UBXYt+ojcmxMktzzuyonYIFta8CmAASpX+CA+DTGK24KlHjhYI6x2iOJ/TjZF4N7/ACK1oFmEOjIY9IhzOQ==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.11.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tybys/wasm-util": {
|
||||
"version": "0.10.2",
|
||||
"resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.2.tgz",
|
||||
"integrity": "sha512-RoBvJ2X0wuKlWFIjrwffGw1IqZHKQqzIchKaadZZfnNpsAYp2mM0h36JtPCjNDAHGgYez/15uMBpfGwchhiMgg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
@@ -1006,7 +996,6 @@
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
|
||||
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
@@ -1096,7 +1085,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1117,7 +1105,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1138,7 +1125,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1159,7 +1145,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1180,7 +1165,6 @@
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1201,7 +1185,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1222,7 +1205,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1243,7 +1225,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1264,7 +1245,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1285,7 +1265,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1306,7 +1285,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1670,7 +1648,6 @@
|
||||
"version": "2.8.1",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
|
||||
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
|
||||
"dev": true,
|
||||
"license": "0BSD",
|
||||
"optional": true
|
||||
},
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.11.0",
|
||||
"@tauri-apps/api": "^2.11.1",
|
||||
"@tauri-apps/plugin-dialog": "^2.7.1",
|
||||
"element-plus": "^2.14.2",
|
||||
"pinia": "^3.0.4",
|
||||
"vue": "^3.5.34",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { invoke } from '@tauri-apps/api/tauri'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
|
||||
export const useAppStore = defineStore('app', () => {
|
||||
const currentTreeType = ref('demo_library_zh')
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
import { ref, onMounted, watch, computed } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useAppStore } from '../stores/app'
|
||||
import { invoke } from '@tauri-apps/api/tauri'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { Folder, Document, Upload, Clock, UserFilled, FolderOpened, Monitor } from '@element-plus/icons-vue'
|
||||
import { open } from '@tauri-apps/api/dialog'
|
||||
import { open } from '@tauri-apps/plugin-dialog'
|
||||
|
||||
const router = useRouter()
|
||||
const appStore = useAppStore()
|
||||
|
||||
Reference in New Issue
Block a user