mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-22 14:35:41 +00:00
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:
@@ -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::*;
|
||||
|
||||
Reference in New Issue
Block a user