feat: 支持解析联合投稿 (#681)
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
pub mod rule;
|
||||
pub mod string_vec;
|
||||
pub mod upper_vec;
|
||||
|
||||
48
crates/bili_sync_entity/src/custom_type/upper_vec.rs
Normal file
48
crates/bili_sync_entity/src/custom_type/upper_vec.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use sea_orm::FromJsonQueryResult;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Upper<T, S> {
|
||||
pub mid: T,
|
||||
pub name: S,
|
||||
pub face: S,
|
||||
pub title: Option<S>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, FromJsonQueryResult)]
|
||||
pub struct UpperVec(pub Vec<Upper<i64, String>>);
|
||||
|
||||
impl From<Vec<Upper<i64, String>>> for UpperVec {
|
||||
fn from(value: Vec<Upper<i64, String>>) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<UpperVec> for Vec<Upper<i64, String>> {
|
||||
fn from(value: UpperVec) -> Self {
|
||||
value.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy> Upper<T, String> {
|
||||
pub fn as_ref(&self) -> Upper<T, &str> {
|
||||
Upper {
|
||||
mid: self.mid,
|
||||
name: self.name.as_str(),
|
||||
face: self.face.as_str(),
|
||||
title: self.title.as_deref(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S: AsRef<str>> Upper<T, S> {
|
||||
pub fn role(&self) -> Cow<'_, str> {
|
||||
if let Some(title) = &self.title {
|
||||
Cow::Owned(format!("{}「{}」", self.name.as_ref(), title.as_ref()))
|
||||
} else {
|
||||
Cow::Borrowed(self.name.as_ref())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.15
|
||||
|
||||
use either::Either;
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
use crate::string_vec::StringVec;
|
||||
use crate::upper_vec::{Upper, UpperVec};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Default)]
|
||||
#[sea_orm(table_name = "video")]
|
||||
@@ -16,6 +18,7 @@ pub struct Model {
|
||||
pub upper_id: i64,
|
||||
pub upper_name: String,
|
||||
pub upper_face: String,
|
||||
pub staff: Option<UpperVec>,
|
||||
pub name: String,
|
||||
pub path: String,
|
||||
pub category: i32,
|
||||
@@ -33,6 +36,21 @@ pub struct Model {
|
||||
pub created_at: String,
|
||||
}
|
||||
|
||||
impl Model {
|
||||
pub fn uppers(&self) -> Either<impl Iterator<Item = Upper<i64, &str>>, impl Iterator<Item = Upper<i64, &str>>> {
|
||||
if let Some(staff) = self.staff.as_ref() {
|
||||
Either::Left(staff.0.iter().map(|u| u.as_ref()))
|
||||
} else {
|
||||
Either::Right(std::iter::once(Upper::<i64, &str> {
|
||||
mid: self.upper_id,
|
||||
name: self.upper_name.as_str(),
|
||||
face: self.upper_face.as_str(),
|
||||
title: None,
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::page::Entity")]
|
||||
|
||||
Reference in New Issue
Block a user