feat: 支持筛选视频的有效性 (#673)
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
use std::borrow::Borrow;
|
||||
|
||||
use bili_sync_entity::video;
|
||||
use bili_sync_migration::SimpleExpr;
|
||||
use itertools::Itertools;
|
||||
use sea_orm::{Condition, ConnectionTrait, DatabaseTransaction};
|
||||
use sea_orm::{ColumnTrait, Condition, ConnectionTrait, DatabaseTransaction};
|
||||
|
||||
use crate::api::request::StatusFilter;
|
||||
use crate::api::request::{StatusFilter, ValidationFilter};
|
||||
use crate::api::response::{PageInfo, SimplePageInfo, SimpleVideoInfo, VideoInfo};
|
||||
use crate::utils::status::VideoStatus;
|
||||
|
||||
@@ -18,6 +20,20 @@ impl StatusFilter {
|
||||
}
|
||||
}
|
||||
|
||||
impl ValidationFilter {
|
||||
pub fn to_video_query(&self) -> SimpleExpr {
|
||||
match self {
|
||||
ValidationFilter::Invalid => video::Column::Valid.eq(false),
|
||||
ValidationFilter::Skipped => video::Column::Valid
|
||||
.eq(true)
|
||||
.and(video::Column::ShouldDownload.eq(false)),
|
||||
ValidationFilter::Normal => video::Column::Valid
|
||||
.eq(true)
|
||||
.and(video::Column::ShouldDownload.eq(true)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait VideoRecord {
|
||||
fn as_id_status_tuple(&self) -> (i32, u32);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,14 @@ pub enum StatusFilter {
|
||||
Waiting,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ValidationFilter {
|
||||
Skipped,
|
||||
Invalid,
|
||||
Normal,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct VideosRequest {
|
||||
pub collection: Option<i32>,
|
||||
@@ -20,6 +28,7 @@ pub struct VideosRequest {
|
||||
pub watch_later: Option<i32>,
|
||||
pub query: Option<String>,
|
||||
pub status_filter: Option<StatusFilter>,
|
||||
pub validation_filter: Option<ValidationFilter>,
|
||||
pub page: Option<u64>,
|
||||
pub page_size: Option<u64>,
|
||||
}
|
||||
@@ -38,6 +47,7 @@ pub struct ResetFilteredVideoStatusRequest {
|
||||
pub watch_later: Option<i32>,
|
||||
pub query: Option<String>,
|
||||
pub status_filter: Option<StatusFilter>,
|
||||
pub validation_filter: Option<ValidationFilter>,
|
||||
#[serde(default)]
|
||||
pub force: bool,
|
||||
}
|
||||
@@ -75,6 +85,7 @@ pub struct UpdateFilteredVideoStatusRequest {
|
||||
pub watch_later: Option<i32>,
|
||||
pub query: Option<String>,
|
||||
pub status_filter: Option<StatusFilter>,
|
||||
pub validation_filter: Option<ValidationFilter>,
|
||||
#[serde(default)]
|
||||
#[validate(nested)]
|
||||
pub video_updates: Vec<StatusUpdate>,
|
||||
|
||||
@@ -65,6 +65,9 @@ pub async fn get_videos(
|
||||
if let Some(status_filter) = params.status_filter {
|
||||
query = query.filter(status_filter.to_video_query());
|
||||
}
|
||||
if let Some(validation_filter) = params.validation_filter {
|
||||
query = query.filter(validation_filter.to_video_query());
|
||||
}
|
||||
let total_count = query.clone().count(&db).await?;
|
||||
let (page, page_size) = if let (Some(page), Some(page_size)) = (params.page, params.page_size) {
|
||||
(page, page_size)
|
||||
@@ -226,6 +229,9 @@ pub async fn reset_filtered_video_status(
|
||||
if let Some(status_filter) = request.status_filter {
|
||||
query = query.filter(status_filter.to_video_query());
|
||||
}
|
||||
if let Some(validation_filter) = request.validation_filter {
|
||||
query = query.filter(validation_filter.to_video_query());
|
||||
}
|
||||
let all_videos = query.into_partial_model::<SimpleVideoInfo>().all(&db).await?;
|
||||
let all_pages = page::Entity::find()
|
||||
.filter(page::Column::VideoId.is_in(all_videos.iter().map(|v| v.id)))
|
||||
@@ -362,6 +368,9 @@ pub async fn update_filtered_video_status(
|
||||
if let Some(status_filter) = request.status_filter {
|
||||
query = query.filter(status_filter.to_video_query());
|
||||
}
|
||||
if let Some(validation_filter) = request.validation_filter {
|
||||
query = query.filter(validation_filter.to_video_query());
|
||||
}
|
||||
let mut all_videos = query.into_partial_model::<SimpleVideoInfo>().all(&db).await?;
|
||||
let mut all_pages = page::Entity::find()
|
||||
.filter(page::Column::VideoId.is_in(all_videos.iter().map(|v| v.id)))
|
||||
|
||||
Reference in New Issue
Block a user