Skip to content

Commit aef7552

Browse files
committed
docs: add code comments
1 parent 1c7b70f commit aef7552

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

public/app-core.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@
309309
function startServerStatusSync() {
310310
if (state.statusTimer) return;
311311
syncServerStatus();
312+
// 托盘也能启动/停止服务,管理端窗口需要持续同步后台状态。
312313
state.statusTimer = window.setInterval(syncServerStatus, 1000);
313314
}
314315

@@ -391,6 +392,7 @@
391392
function connectEvents() {
392393
const status = $('status');
393394
if (state.events) state.events.close();
395+
// 共享列表由服务端 SSE 推送,管理端和客户端保持同一份实时视图。
394396
const events = new EventSource(`${state.apiBase}/api/events`);
395397
state.events = events;
396398
events.onopen = () => { status.textContent = t('synced'); };
@@ -443,6 +445,7 @@
443445
});
444446

445447
try {
448+
// 这里只提交本机路径,实际文件仍留在原位置,避免复制大文件。
446449
await request('/api/local-file', {
447450
method: 'POST',
448451
headers: { 'content-type': 'application/json' },

src-tauri/src/server.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ pub async fn start(port: u16) -> Result<ServerInfo, String> {
242242
.map(|address| address.ip.clone())
243243
.unwrap_or_else(|| "127.0.0.1".to_string());
244244

245+
// 管理端接口只允许本机调用;启动时缓存当前机器地址,避免局域网客户端误触管理能力。
245246
let mut local_addresses = HashSet::from([
246247
IpAddr::V4(Ipv4Addr::LOCALHOST),
247248
IpAddr::V6(std::net::Ipv6Addr::LOCALHOST),
@@ -268,6 +269,7 @@ pub async fn start(port: u16) -> Result<ServerInfo, String> {
268269
};
269270
let (download_shutdown_tx, mut download_shutdown_rx) = oneshot::channel::<()>();
270271
let download_state = state.clone();
272+
// 下载状态单独按秒聚合后通过 SSE 推给管理端,用于显示正在下载和速率。
271273
tokio::spawn(async move {
272274
let mut interval = tokio::time::interval(Duration::from_secs(1));
273275
loop {
@@ -562,6 +564,7 @@ async fn upload(
562564
}
563565
}
564566

567+
// 管理端共享文件必须走系统文件选择器和本机路径登记,不能退化成 HTTP 上传复制。
565568
if source == "admin" {
566569
for item in &items {
567570
let _ = fs::remove_file(&item.storage_path).await;
@@ -647,6 +650,7 @@ async fn download(
647650
let metadata = file.metadata().await?;
648651
let file_size = metadata.len();
649652
let fallback_name = ascii_fallback_name(&item.title);
653+
// 浏览器、播放器和下载器会依赖 Range;这里同时支持完整下载和分段下载。
650654
let range = parse_range_header(headers.get(RANGE), file_size)?;
651655
let download_id = item.id.clone();
652656
mark_download_started(&state, &download_id).await;
@@ -728,6 +732,7 @@ async fn download(
728732
if read == 0 {
729733
break;
730734
}
735+
// 每个分片写入下载计数,后台任务会把它折算成管理端看到的速率。
731736
record_download_bytes(&state, &download_id, read as u64).await;
732737
yield Ok::<Bytes, std::io::Error>(Bytes::copy_from_slice(&buffer[..read]));
733738
}
@@ -836,6 +841,7 @@ fn public_items(items: &[Item]) -> Vec<PublicItem> {
836841
mime: item.mime.clone(),
837842
size: item.size,
838843
source: item.source.clone(),
844+
// 文件可能被用户从原位置移动或删除,列表每次输出时都重新标记可用性。
839845
exists: item.kind == "text" || Path::new(&item.storage_path).exists(),
840846
created_at: item.created_at.clone(),
841847
updated_at: item.updated_at.clone(),

0 commit comments

Comments
 (0)