refactor(lib_commands): centralise HTTP-stream-to-disk pattern in file_transfer

Pull the duplicated `subsonic UA + timeout client builder` and
`stream → .part → rename → cleanup` flow out of cache/offline.rs,
sync/device.rs, and sync/batch.rs into a new lib_commands/file_transfer
module.

- subsonic_http_client(timeout): standard UA + single timeout. Used by
  the 3 simple-timeout sites (offline track, sync_track, batch sync).
  download_update / download_zip / fetch_netease_lyrics keep their own
  builders since they need separate connect+overall timeouts or extra
  headers.
- stream_to_file(response, dest): chunked HTTP body → file (moved from
  cache/offline.rs, where it was the de-facto shared helper anyway).
- finalize_streamed_download(response, dest, part): stream to .part
  then rename, with best-effort cleanup of .part on any failure.

Behaviour delta: the offline + device single-track flows now also clean
up an orphan .part file when the final rename fails — previously only
the batch sync did this. Strictly safer; no observable change on the
success path.

downloads.rs (download_update / download_zip) keeps its inline progress
chunk loops — those emit per-chunk progress events with flow-specific
payload shapes and intervals; sharing them would force a callback API
that's heavier than the duplication it removes.

Net delta: -53 LOC across the 3 call sites.
This commit is contained in:
Psychotoxical
2026-05-08 11:53:06 +02:00
parent 66cbf25469
commit 635a59f133
5 changed files with 66 additions and 62 deletions
+2
View File
@@ -2,10 +2,12 @@ use super::*;
mod app_api;
mod cache;
mod file_transfer;
mod sync;
mod ui;
pub(crate) use app_api::*;
pub(crate) use cache::*;
pub(crate) use file_transfer::*;
pub(crate) use sync::*;
pub(crate) use ui::*;