Update download task execution and improve docs

Refactored the DownloadTask::execute method to return DownloadStatus and adjusted its visibility. Enhanced DActor message handling to update stream info after download execution. Updated README and introduction guide with improved instructions for background running and systemd service configuration.
This commit is contained in:
ForgQi committed 2025-10-27 02:05:23 +08:00
1 parent f5f2998d16
commit b497749744
3 files changed
+21 -17

No files matched your search

+3 -1
View File
@@ -83,7 +83,9 @@ Options:
2. 安装:`uv tool install biliup`
3. 启动:`biliup server --auth`
4. 访问 WebUI:`http://your-ip:19159`
* 后台运行 `nohup biliup server --auth &`
* 后台运行
1. `nohup biliup server --auth &`
2. [请查看参考](https://biliup.github.io/biliup/docs/guide/introduction/#linuxxia-pei-zhi-kai-ji-zi-qi)
### Termux
- 详见[Wiki](https://github.com/biliup/biliup/wiki/Termux-%E4%B8%AD%E4%BD%BF%E7%94%A8-biliup)
+17 -13
View File
@@ -1,11 +1,11 @@
use crate::server::common::upload::UploaderMessage;
use crate::server::core::downloader::{DownloadStatus, Downloader, SegmentEvent, SegmentInfo};
use crate::server::core::monitor::RoomsHandle;
use crate::server::core::plugin::DownloadPlugin;
use crate::server::core::plugin::{DownloadPlugin, StreamStatus};
use crate::server::errors::{AppError, AppResult};
use crate::server::infrastructure::context::{Context, Worker, WorkerStatus};
use async_channel::{Receiver, Sender};
use error_stack::{ResultExt, bail};
use error_stack::{ResultExt, bail, Report};
use std::fs;
use std::path::Path;
use std::sync::Arc;
@@ -277,7 +277,7 @@ impl DownloadTask {
}
}
pub async fn execute(self, components: DownloadComponents) -> AppResult<()> {
pub(self) async fn execute(self, components: DownloadComponents) -> AppResult<DownloadStatus> {
// 创建事件处理器
let processor = SegmentEventProcessor::new(components.uploader.clone(), self.ctx.clone());
@@ -295,14 +295,8 @@ impl DownloadTask {
.change_context(AppError::Custom("Failed to download segment".into()))?;
// 处理结果
match result {
DownloadStatus::Downloading => {}
DownloadStatus::SegmentCompleted => {}
DownloadStatus::StreamEnded => {}
DownloadStatus::Error(_) => {}
}
info!(result=?result, "finished downloading");
Ok(())
Ok(result)
}
async fn initialize_components(&self, uploader: Sender<UploaderMessage>) -> DownloadComponents {
@@ -371,10 +365,10 @@ impl DActor {
/// * `msg` - 要处理的下载消息
async fn handle_message(&mut self, msg: DownloaderMessage) {
match msg {
DownloaderMessage::Start(plugin, ctx, rooms_handle) => {
DownloaderMessage::Start(plugin, mut ctx, rooms_handle) => {
let worker = ctx.worker.clone();
// 创建下载任务
let task = DownloadTask::new(plugin, ctx, rooms_handle.clone());
let task = DownloadTask::new(plugin.clone(), ctx.clone(), rooms_handle.clone());
// 初始化组件
let components = task.initialize_components(self.sender.clone()).await;
@@ -391,9 +385,19 @@ impl DActor {
.toggle(worker, WorkerStatus::Working(components.downloader.clone()))
.await;
// 执行下载(使用 Result 链式处理)
// 执行下载
let result = task.execute(components).await;
match plugin.check_status(&mut ctx).await {
Ok(StreamStatus::Live {stream_info}) => {
ctx.stream_info.raw_stream_url = stream_info.raw_stream_url;
println!("stream_info=?stream_info");
}
Ok(StreamStatus::Offline) => {}
Ok(StreamStatus::Unknown) => {}
Err(_) => {}
}
guard.cleanup().await;
info!("Handling message: {:?} done", result);
}
+1 -3
View File
@@ -250,9 +250,7 @@ After=network-online.target
[Service]
Type=simple
WorkingDirectory=[在此填入你的config所在目录]
ExecStart=/usr/bin/biliup -v
ExecReload=/usr/bin/biliup restart
ExecStop=/usr/bin/biliup stop
ExecStart=/usr/bin/biliup server --auth
[Install]
WantedBy=default.target