Update deps & fix server upload/download

Bump dependencies (Cargo.toml + Cargo.lock) to newer crate versions and adapt code to API changes. Refactor server-side upload/download logic, the upload_streamer model, and related API endpoints to improve streaming handling, buffer/error propagation and compatibility with updated crates (e.g. tokio-tungstenite/futures/etc.). These changes align the codebase with the upgraded dependency set and fix streaming/endpoint issues introduced by those upgrades.
This commit is contained in:
ForgQi committed 2026-07-11 01:57:48 +08:00
1 parent 58dc75b6ca
commit ddc29f63b4
7 files changed
+817 -721

No files matched your search

Generated
+738 -714
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -8,7 +8,7 @@ members = [
resolver = "3"
[workspace.package]
version = "1.2.1"
version = "1.2.2"
[workspace.dependencies]
serde = { version = "1.0", features = ["derive"] }
+2 -5
View File
@@ -12,7 +12,7 @@ use crate::server::errors::{AppError, AppResult};
use crate::server::infrastructure::connection_pool::ConnectionManager;
use crate::server::infrastructure::models::live_streamer::InsertLiveStreamer;
use crate::server::infrastructure::models::upload_streamer::{
InsertUploadStreamer, UploadStreamer,
InsertUploadStreamer, UploadStreamer, is_noop_uploader,
};
use crate::server::infrastructure::repositories;
use crate::server::infrastructure::service_register::ServiceRegister;
@@ -182,10 +182,7 @@ fn to_upload_streamer_insert(
global_uploader: Option<String>,
) -> AppResult<Option<InsertUploadStreamer>> {
let uploader = streamer.uploader.clone().or(global_uploader);
if uploader
.as_deref()
.is_some_and(|value| value.eq_ignore_ascii_case("noop"))
{
if is_noop_uploader(uploader.as_deref()) {
return Ok(None);
}
@@ -556,6 +556,14 @@ pub async fn post_uploads(
Json(json_data): Json<PostUploads>,
) -> Result<Json<serde_json::Value>, Response> {
let upload_config = json_data.params;
if upload_config.is_noop_uploader() {
info!(
uploader = ?upload_config.uploader,
"Skipping page upload because uploader is Noop"
);
return Ok(Json(json!({})));
}
let (line, limit, submit_api) = {
let config = config.read().unwrap();
let line = UploadLine::from_str(&config.lines, true).ok();
@@ -280,9 +280,18 @@ impl DownloadTask {
}
};
let download_config = ctx.download_config(stream);
info!(
page_url = streamer.url,
stream_url = download_config.url,
platform = stream.platform,
suffix = download_config.suffix,
"开始下载,已解析流直链"
);
let result = self
.downloader
.download(Box::new(hook), ctx.download_config(stream))
.download(Box::new(hook), download_config)
.await
.change_context(AppError::Custom("Failed to download segment".into()))?;
@@ -87,6 +87,21 @@ where
Ok(())
}
async fn process_without_upload<F>(
rx: Inspect<Receiver<SegmentInfo>, F>,
ctx: &Context,
) -> AppResult<()>
where
F: FnMut(&SegmentInfo),
{
let mut paths = Vec::new();
pin!(rx);
while let Some(event) = rx.next().await {
paths.extend(segment_paths(&event));
}
execute_postprocessor(paths, ctx).await
}
async fn initialize_upload_context(
config: &Config,
client: &StatelessClient,
@@ -508,6 +523,13 @@ impl UActor {
});
});
let result = match ctx.upload_config() {
Some(config) if config.is_noop_uploader() => {
info!(
uploader = ?config.uploader,
"Skipping upload because uploader is Noop"
);
process_without_upload(inspect, &ctx).await
}
Some(config) => process_with_upload(inspect, &ctx, config).await,
None => {
let mut paths = Vec::new();
@@ -86,3 +86,39 @@ pub struct InsertUploadStreamer {
pub extra_fields: Option<String>,
pub is_only_self: Option<u8>,
}
pub(crate) fn is_noop_uploader(uploader: Option<&str>) -> bool {
uploader
.map(str::trim)
.is_some_and(|value| value.eq_ignore_ascii_case("noop"))
}
impl UploadStreamer {
pub(crate) fn is_noop_uploader(&self) -> bool {
is_noop_uploader(self.uploader.as_deref())
}
}
#[cfg(test)]
mod tests {
use super::is_noop_uploader;
#[test]
fn noop_uploader_matches_case_insensitively() {
assert!(is_noop_uploader(Some("Noop")));
assert!(is_noop_uploader(Some("noop")));
assert!(is_noop_uploader(Some("NOOP")));
}
#[test]
fn noop_uploader_ignores_surrounding_whitespace() {
assert!(is_noop_uploader(Some(" Noop ")));
}
#[test]
fn noop_uploader_rejects_missing_or_other_uploaders() {
assert!(!is_noop_uploader(None));
assert!(!is_noop_uploader(Some("")));
assert!(!is_noop_uploader(Some("biliup-rs")));
}
}