音乐模块调整

This commit is contained in:
2026-09-12 15:47:16 +08:00
parent d702ed0d31
commit ffa410b399
33 changed files with 5452 additions and 2237 deletions
+3 -76
View File
@@ -5,7 +5,6 @@
//! 对照 FeiNiuMusic(Flutter) `api_client.dart` 的第三方纯前端实现翻译。
//! 所有对 NAS 的 HTTP 请求在本模块收敛(页面/命令层不直接发请求)。
use std::collections::HashMap;
use std::path::Path;
use std::sync::{Arc, Mutex};
use std::time::Duration;
@@ -21,12 +20,11 @@ pub use conn::normalize_base_url;
mod cache;
mod conn;
mod fnconnect;
mod fnos;
pub mod proxy;
pub mod webdav;
pub use cache::CacheManager;
pub use fnconnect::{extract_fn_id, resolve_base_url};
pub use fnos::FnOsSession;
use conn::{generate_device_id, sha256_hex};
use proxy::{ProxyCfg, ProxyShared};
@@ -90,8 +88,6 @@ pub struct Feiniu {
conn: Mutex<Conn>,
proxy: Mutex<Option<(u16, ProxyShared)>>,
cache: CacheManager,
/// fnOS 文件服务会话:connection id → 会话
fnos_sessions: Mutex<HashMap<String, Arc<FnOsSession>>>,
}
impl Default for Feiniu {
@@ -108,7 +104,6 @@ impl Default for Feiniu {
}),
proxy: Mutex::new(None),
cache: CacheManager::new(Path::new("placeholder")), // 由 set_cache_root 重建
fnos_sessions: Mutex::new(HashMap::new()),
}
}
}
@@ -435,76 +430,8 @@ impl Feiniu {
Ok(self.cache.hit(guid))
}
// ===== fnOS 文件服务(P6:上传/删除) =====
/// fnOS 登录:为指定连接建立文件服务会话。
pub async fn fnos_login(
&self,
connection_id: &str,
base_url: &str,
username: &str,
password: &str,
) -> Result<(), String> {
let session = Arc::new(FnOsSession::connect(base_url, username, password).await?);
if let Ok(mut m) = self.fnos_sessions.lock() {
m.insert(connection_id.to_string(), session);
}
Ok(())
}
pub fn fnos_logout(&self, connection_id: &str) {
if let Ok(mut m) = self.fnos_sessions.lock() {
m.remove(connection_id);
}
}
pub fn fnos_logged_in(&self, connection_id: &str) -> bool {
self.fnos_sessions
.lock()
.map(|m| m.contains_key(connection_id))
.unwrap_or(false)
}
/// 上传本地文件到 NAS(走 fnOS 会话;会话缺失返回 Err)。
pub async fn fnos_upload(
&self,
connection_id: &str,
local_path: &std::path::Path,
nas_path: &str,
) -> Result<String, String> {
let session = self
.fnos_sessions
.lock()
.map(|m| m.get(connection_id).cloned())
.ok()
.flatten()
.ok_or_else(|| "请先登录 NAS 文件服务(设置 → 连接 → fnOS 登录)")?;
fnos::upload_file(&session, local_path, nas_path, 2).await
}
/// 删除 NAS 文件。
pub async fn fnos_delete(&self, connection_id: &str, nas_path: &str) -> Result<(), String> {
let session = self
.fnos_sessions
.lock()
.map(|m| m.get(connection_id).cloned())
.ok()
.flatten()
.ok_or_else(|| "请先登录 NAS 文件服务")?;
session.delete_file(nas_path).await
}
/// 列出 NAS 目录。
pub async fn fnos_list(&self, connection_id: &str, path: &str) -> Result<Value, String> {
let session = self
.fnos_sessions
.lock()
.map(|m| m.get(connection_id).cloned())
.ok()
.flatten()
.ok_or_else(|| "请先登录 NAS 文件服务")?;
session.list(path).await
}
// ===== WebDAV 传输(下载到飞牛 / 曲库增删)=====
// 无状态:配置由前端每次调用传入,实现在 webdav 模块,命令层直接调用。
async fn ensure_proxy(&self) -> Result<u16, String> {
if let Ok(g) = self.proxy.lock() {