mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-07-09 06:23:46 +08:00
chore: 将 video list model / video list 重命名为 video source (#260)
This commit is contained in:
@@ -9,10 +9,10 @@ use sea_orm::sea_query::{OnConflict, SimpleExpr};
|
||||
use sea_orm::ActiveValue::Set;
|
||||
use sea_orm::{DatabaseConnection, Unchanged};
|
||||
|
||||
use crate::adapter::{VideoListModel, VideoListModelEnum, _ActiveModel};
|
||||
use crate::adapter::{VideoSource, VideoSourceEnum, _ActiveModel};
|
||||
use crate::bilibili::{BiliClient, Collection, CollectionItem, CollectionType, VideoInfo};
|
||||
|
||||
impl VideoListModel for collection::Model {
|
||||
impl VideoSource for collection::Model {
|
||||
fn filter_expr(&self) -> SimpleExpr {
|
||||
video::Column::CollectionId.eq(self.id)
|
||||
}
|
||||
@@ -77,7 +77,7 @@ pub(super) async fn collection_from<'a>(
|
||||
bili_client: &'a BiliClient,
|
||||
connection: &DatabaseConnection,
|
||||
) -> Result<(
|
||||
VideoListModelEnum,
|
||||
VideoSourceEnum,
|
||||
Pin<Box<dyn Stream<Item = Result<VideoInfo>> + 'a + Send>>,
|
||||
)> {
|
||||
let collection = Collection::new(bili_client, collection_item);
|
||||
|
||||
@@ -9,10 +9,10 @@ use sea_orm::sea_query::{OnConflict, SimpleExpr};
|
||||
use sea_orm::ActiveValue::Set;
|
||||
use sea_orm::{DatabaseConnection, Unchanged};
|
||||
|
||||
use crate::adapter::{VideoListModel, VideoListModelEnum, _ActiveModel};
|
||||
use crate::adapter::{VideoSource, VideoSourceEnum, _ActiveModel};
|
||||
use crate::bilibili::{BiliClient, FavoriteList, VideoInfo};
|
||||
|
||||
impl VideoListModel for favorite::Model {
|
||||
impl VideoSource for favorite::Model {
|
||||
fn filter_expr(&self) -> SimpleExpr {
|
||||
video::Column::FavoriteId.eq(self.id)
|
||||
}
|
||||
@@ -68,7 +68,7 @@ pub(super) async fn favorite_from<'a>(
|
||||
bili_client: &'a BiliClient,
|
||||
connection: &DatabaseConnection,
|
||||
) -> Result<(
|
||||
VideoListModelEnum,
|
||||
VideoSourceEnum,
|
||||
Pin<Box<dyn Stream<Item = Result<VideoInfo>> + 'a + Send>>,
|
||||
)> {
|
||||
let favorite = FavoriteList::new(bili_client, fid.to_owned());
|
||||
|
||||
@@ -26,15 +26,15 @@ use crate::adapter::watch_later::watch_later_from;
|
||||
use crate::bilibili::{BiliClient, CollectionItem, VideoInfo};
|
||||
|
||||
#[enum_dispatch]
|
||||
pub enum VideoListModelEnum {
|
||||
pub enum VideoSourceEnum {
|
||||
Favorite,
|
||||
Collection,
|
||||
Submission,
|
||||
WatchLater,
|
||||
}
|
||||
|
||||
#[enum_dispatch(VideoListModelEnum)]
|
||||
pub trait VideoListModel {
|
||||
#[enum_dispatch(VideoSourceEnum)]
|
||||
pub trait VideoSource {
|
||||
/// 获取特定视频列表的筛选条件
|
||||
fn filter_expr(&self) -> SimpleExpr;
|
||||
|
||||
@@ -48,7 +48,7 @@ pub trait VideoListModel {
|
||||
fn get_latest_row_at(&self) -> DateTime;
|
||||
|
||||
/// 更新视频 model 中记录的最新时间,此处返回需要更新的 ActiveModel,接着调用 save 方法执行保存
|
||||
/// 不同 VideoListModel 返回的类型不同,为了 VideoListModel 的 object safety 不能使用 impl Trait
|
||||
/// 不同 VideoSource 返回的类型不同,为了 VideoSource 的 object safety 不能使用 impl Trait
|
||||
/// Box<dyn ActiveModelTrait> 又提示 ActiveModelTrait 没有 object safety,因此手写一个 Enum 静态分发
|
||||
fn update_latest_row_at(&self, datetime: DateTime) -> _ActiveModel;
|
||||
|
||||
@@ -79,13 +79,13 @@ pub enum Args<'a> {
|
||||
Submission { upper_id: &'a str },
|
||||
}
|
||||
|
||||
pub async fn video_list_from<'a>(
|
||||
pub async fn video_source_from<'a>(
|
||||
args: Args<'a>,
|
||||
path: &Path,
|
||||
bili_client: &'a BiliClient,
|
||||
connection: &DatabaseConnection,
|
||||
) -> Result<(
|
||||
VideoListModelEnum,
|
||||
VideoSourceEnum,
|
||||
Pin<Box<dyn Stream<Item = Result<VideoInfo>> + 'a + Send>>,
|
||||
)> {
|
||||
match args {
|
||||
|
||||
@@ -9,10 +9,10 @@ use sea_orm::sea_query::{OnConflict, SimpleExpr};
|
||||
use sea_orm::ActiveValue::Set;
|
||||
use sea_orm::{DatabaseConnection, Unchanged};
|
||||
|
||||
use crate::adapter::{VideoListModel, VideoListModelEnum, _ActiveModel};
|
||||
use crate::adapter::{VideoSource, VideoSourceEnum, _ActiveModel};
|
||||
use crate::bilibili::{BiliClient, Submission, VideoInfo};
|
||||
|
||||
impl VideoListModel for submission::Model {
|
||||
impl VideoSource for submission::Model {
|
||||
fn filter_expr(&self) -> SimpleExpr {
|
||||
video::Column::SubmissionId.eq(self.id)
|
||||
}
|
||||
@@ -68,7 +68,7 @@ pub(super) async fn submission_from<'a>(
|
||||
bili_client: &'a BiliClient,
|
||||
connection: &DatabaseConnection,
|
||||
) -> Result<(
|
||||
VideoListModelEnum,
|
||||
VideoSourceEnum,
|
||||
Pin<Box<dyn Stream<Item = Result<VideoInfo>> + 'a + Send>>,
|
||||
)> {
|
||||
let submission = Submission::new(bili_client, upper_id.to_owned());
|
||||
|
||||
@@ -9,10 +9,10 @@ use sea_orm::sea_query::{OnConflict, SimpleExpr};
|
||||
use sea_orm::ActiveValue::Set;
|
||||
use sea_orm::{DatabaseConnection, Unchanged};
|
||||
|
||||
use crate::adapter::{VideoListModel, VideoListModelEnum, _ActiveModel};
|
||||
use crate::adapter::{VideoSource, VideoSourceEnum, _ActiveModel};
|
||||
use crate::bilibili::{BiliClient, VideoInfo, WatchLater};
|
||||
|
||||
impl VideoListModel for watch_later::Model {
|
||||
impl VideoSource for watch_later::Model {
|
||||
fn filter_expr(&self) -> SimpleExpr {
|
||||
video::Column::WatchLaterId.eq(self.id)
|
||||
}
|
||||
@@ -67,7 +67,7 @@ pub(super) async fn watch_later_from<'a>(
|
||||
bili_client: &'a BiliClient,
|
||||
connection: &DatabaseConnection,
|
||||
) -> Result<(
|
||||
VideoListModelEnum,
|
||||
VideoSourceEnum,
|
||||
Pin<Box<dyn Stream<Item = Result<VideoInfo>> + 'a + Send>>,
|
||||
)> {
|
||||
let watch_later = WatchLater::new(bili_client);
|
||||
|
||||
Reference in New Issue
Block a user