feat: 确保 video stream 在出现错误时返回 Err (#231)

This commit is contained in:
ᴀᴍᴛᴏᴀᴇʀ
2025-01-24 13:17:12 +08:00
committed by GitHub
parent 7c220f0d2b
commit 9e5a8b0573
11 changed files with 149 additions and 115 deletions
+5 -2
View File
@@ -98,7 +98,10 @@ pub(super) async fn collection_from<'a>(
path: &Path,
bili_client: &'a BiliClient,
connection: &DatabaseConnection,
) -> Result<(Box<dyn VideoListModel>, Pin<Box<dyn Stream<Item = VideoInfo> + 'a>>)> {
) -> Result<(
Box<dyn VideoListModel>,
Pin<Box<dyn Stream<Item = Result<VideoInfo>> + 'a>>,
)> {
let collection = Collection::new(bili_client, collection_item);
let collection_info = collection.get_info().await?;
collection::Entity::insert(collection::ActiveModel {
@@ -133,6 +136,6 @@ pub(super) async fn collection_from<'a>(
.await?
.context("collection not found")?,
),
Box::pin(collection.into_simple_video_stream()),
Box::pin(collection.into_video_stream()),
))
}
+4 -1
View File
@@ -70,7 +70,10 @@ pub(super) async fn favorite_from<'a>(
path: &Path,
bili_client: &'a BiliClient,
connection: &DatabaseConnection,
) -> Result<(Box<dyn VideoListModel>, Pin<Box<dyn Stream<Item = VideoInfo> + 'a>>)> {
) -> Result<(
Box<dyn VideoListModel>,
Pin<Box<dyn Stream<Item = Result<VideoInfo>> + 'a>>,
)> {
let favorite = FavoriteList::new(bili_client, fid.to_owned());
let favorite_info = favorite.get_info().await?;
favorite::Entity::insert(favorite::ActiveModel {
+4 -1
View File
@@ -67,7 +67,10 @@ pub async fn video_list_from<'a>(
path: &Path,
bili_client: &'a BiliClient,
connection: &DatabaseConnection,
) -> Result<(Box<dyn VideoListModel>, Pin<Box<dyn Stream<Item = VideoInfo> + 'a>>)> {
) -> Result<(
Box<dyn VideoListModel>,
Pin<Box<dyn Stream<Item = Result<VideoInfo>> + 'a>>,
)> {
match args {
Args::Favorite { fid } => favorite_from(fid, path, bili_client, connection).await,
Args::Collection { collection_item } => collection_from(collection_item, path, bili_client, connection).await,
+4 -1
View File
@@ -82,7 +82,10 @@ pub(super) async fn submission_from<'a>(
path: &Path,
bili_client: &'a BiliClient,
connection: &DatabaseConnection,
) -> Result<(Box<dyn VideoListModel>, Pin<Box<dyn Stream<Item = VideoInfo> + 'a>>)> {
) -> Result<(
Box<dyn VideoListModel>,
Pin<Box<dyn Stream<Item = Result<VideoInfo>> + 'a>>,
)> {
let submission = Submission::new(bili_client, upper_id.to_owned());
let upper = submission.get_info().await?;
submission::Entity::insert(submission::ActiveModel {
+4 -1
View File
@@ -66,7 +66,10 @@ pub(super) async fn watch_later_from<'a>(
path: &Path,
bili_client: &'a BiliClient,
connection: &DatabaseConnection,
) -> Result<(Box<dyn VideoListModel>, Pin<Box<dyn Stream<Item = VideoInfo> + 'a>>)> {
) -> Result<(
Box<dyn VideoListModel>,
Pin<Box<dyn Stream<Item = Result<VideoInfo>> + 'a>>,
)> {
let watch_later = WatchLater::new(bili_client);
watch_later::Entity::insert(watch_later::ActiveModel {
id: Set(1),