feature: add subscription manage

This commit is contained in:
2025-04-30 01:59:14 +08:00
parent 9fdb778330
commit 4301f1dbab
128 changed files with 2286 additions and 740 deletions

View File

@@ -72,7 +72,15 @@ jwt-authorizer = "0.15.0"
log = "0.4"
async-graphql = { version = "7", features = [] }
async-graphql-axum = "7"
seaography = { version = "1.1" }
seaography = { version = "1.1", features = [
"with-json",
"with-chrono",
"with-time",
"with-uuid",
"with-decimal",
"with-bigdecimal",
"with-postgres-array",
] }
base64 = "0.22.1"
tower = "0.5.2"
tower-http = { version = "0.6", features = [

View File

@@ -366,7 +366,10 @@ impl AuthServiceTrait for OidcAuthService {
}) => crate::models::auth::Model::create_from_oidc(ctx, sub.to_string()).await,
r => r,
}
.map_err(|_| AuthError::FindAuthRecordError)?;
.map_err(|e| {
tracing::error!("Error finding auth record: {:?}", e);
AuthError::FindAuthRecordError
})?;
Ok(AuthUserInfo {
subscriber_auth,

View File

@@ -2,7 +2,10 @@ use std::collections::HashSet;
use async_trait::async_trait;
use sea_orm::{DeriveIden, Statement};
use sea_orm_migration::prelude::{extension::postgres::IntoTypeRef, *};
use sea_orm_migration::{
prelude::{extension::postgres::IntoTypeRef, *},
schema::timestamp_with_time_zone,
};
use crate::migrations::extension::postgres::Type;
@@ -144,6 +147,17 @@ macro_rules! create_postgres_enum_for_active_enum {
};
}
pub fn timestamps_z(t: TableCreateStatement) -> TableCreateStatement {
let mut t = t;
t.col(timestamp_with_time_zone(GeneralIds::CreatedAt).default(Expr::current_timestamp()))
.col(timestamp_with_time_zone(GeneralIds::UpdatedAt).default(Expr::current_timestamp()))
.take()
}
pub fn table_auto_z<T: IntoIden + 'static>(name: T) -> TableCreateStatement {
timestamps_z(Table::create().table(name).if_not_exists().take())
}
#[async_trait]
pub trait CustomSchemaManagerExt {
async fn create_postgres_auto_update_ts_fn(&self, col_name: &str) -> Result<(), DbErr>;

View File

@@ -3,7 +3,7 @@ use sea_orm_migration::{prelude::*, schema::*};
use super::defs::{
Bangumi, CustomSchemaManagerExt, Episodes, GeneralIds, Subscribers, SubscriptionBangumi,
SubscriptionEpisode, Subscriptions,
SubscriptionEpisode, Subscriptions, table_auto_z,
};
use crate::models::{
subscribers::SEED_SUBSCRIBER,
@@ -22,7 +22,7 @@ impl MigrationTrait for Migration {
manager
.create_table(
table_auto(Subscribers::Table)
table_auto_z(Subscribers::Table)
.col(pk_auto(Subscribers::Id))
.col(string(Subscribers::DisplayName))
.col(json_binary_null(Subscribers::BangumiConf))
@@ -57,7 +57,7 @@ impl MigrationTrait for Migration {
manager
.create_table(
table_auto(Subscriptions::Table)
table_auto_z(Subscriptions::Table)
.col(pk_auto(Subscriptions::Id))
.col(string(Subscriptions::DisplayName))
.col(integer(Subscriptions::SubscriberId))
@@ -89,7 +89,7 @@ impl MigrationTrait for Migration {
manager
.create_table(
table_auto(Bangumi::Table)
table_auto_z(Bangumi::Table)
.col(pk_auto(Bangumi::Id))
.col(text_null(Bangumi::MikanBangumiId))
.col(integer(Bangumi::SubscriberId))
@@ -156,7 +156,7 @@ impl MigrationTrait for Migration {
manager
.create_table(
table_auto(SubscriptionBangumi::Table)
table_auto_z(SubscriptionBangumi::Table)
.col(pk_auto(SubscriptionBangumi::Id))
.col(integer(SubscriptionBangumi::SubscriberId))
.col(integer(SubscriptionBangumi::SubscriptionId))
@@ -206,7 +206,7 @@ impl MigrationTrait for Migration {
manager
.create_table(
table_auto(Episodes::Table)
table_auto_z(Episodes::Table)
.col(pk_auto(Episodes::Id))
.col(text_null(Episodes::MikanEpisodeId))
.col(text(Episodes::RawName))
@@ -275,7 +275,7 @@ impl MigrationTrait for Migration {
manager
.create_table(
table_auto(SubscriptionEpisode::Table)
table_auto_z(SubscriptionEpisode::Table)
.col(pk_auto(SubscriptionEpisode::Id))
.col(integer(SubscriptionEpisode::SubscriptionId))
.col(integer(SubscriptionEpisode::EpisodeId))

View File

@@ -23,7 +23,7 @@ impl MigrationTrait for Migration {
manager
.create_table(
table_auto(Downloaders::Table)
table_auto_z(Downloaders::Table)
.col(pk_auto(Downloaders::Id))
.col(text(Downloaders::Endpoint))
.col(string_null(Downloaders::Username))
@@ -78,7 +78,7 @@ impl MigrationTrait for Migration {
manager
.create_table(
table_auto(Downloads::Table)
table_auto_z(Downloads::Table)
.col(pk_auto(Downloads::Id))
.col(string(Downloads::RawName))
.col(string(Downloads::DisplayName))

View File

@@ -1,5 +1,6 @@
use sea_orm_migration::{prelude::*, schema::*};
use super::defs::table_auto_z;
use crate::{
migrations::defs::{CustomSchemaManagerExt, Downloaders, GeneralIds, Subscribers},
models::downloaders::{DownloaderCategory, DownloaderCategoryEnum},
@@ -20,7 +21,7 @@ impl MigrationTrait for Migration {
manager
.create_table(
table_auto(Downloaders::Table)
table_auto_z(Downloaders::Table)
.col(pk_auto(Downloaders::Id))
.col(text(Downloaders::Endpoint))
.col(string_null(Downloaders::Username))

View File

@@ -1,7 +1,7 @@
use async_trait::async_trait;
use sea_orm_migration::{prelude::*, schema::*};
use super::defs::Auth;
use super::defs::{Auth, table_auto_z};
use crate::{
migrations::defs::{CustomSchemaManagerExt, GeneralIds, Subscribers},
models::{
@@ -26,7 +26,7 @@ impl MigrationTrait for Migration {
manager
.create_table(
table_auto(Auth::Table)
table_auto_z(Auth::Table)
.col(pk_auto(Auth::Id))
.col(text(Auth::Pid))
.col(enumeration(

View File

@@ -24,9 +24,9 @@ pub enum AuthType {
#[sea_orm(table_name = "auth")]
pub struct Model {
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub created_at: DateTime,
pub created_at: DateTimeUtc,
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub updated_at: DateTime,
pub updated_at: DateTimeUtc,
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(unique)]

View File

@@ -30,9 +30,9 @@ pub struct BangumiExtra {
#[sea_orm(table_name = "bangumi")]
pub struct Model {
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub created_at: DateTime,
pub created_at: DateTimeUtc,
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub updated_at: DateTime,
pub updated_at: DateTimeUtc,
#[sea_orm(primary_key)]
pub id: i32,
pub mikan_bangumi_id: Option<String>,

View File

@@ -23,9 +23,9 @@ pub enum DownloaderCategory {
#[sea_orm(table_name = "downloaders")]
pub struct Model {
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub created_at: DateTime,
pub created_at: DateTimeUtc,
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub updated_at: DateTime,
pub updated_at: DateTimeUtc,
#[sea_orm(primary_key)]
pub id: i32,
pub category: DownloaderCategory,

View File

@@ -39,9 +39,9 @@ pub enum DownloadMime {
#[sea_orm(table_name = "downloads")]
pub struct Model {
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub created_at: DateTime,
pub created_at: DateTimeUtc,
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub updated_at: DateTime,
pub updated_at: DateTimeUtc,
#[sea_orm(primary_key)]
pub id: i32,
pub raw_name: String,

View File

@@ -28,9 +28,9 @@ pub struct EpisodeExtra {
#[sea_orm(table_name = "episodes")]
pub struct Model {
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub created_at: DateTime,
pub created_at: DateTimeUtc,
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub updated_at: DateTime,
pub updated_at: DateTimeUtc,
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(indexed)]

View File

@@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
use crate::{
app::AppContextTrait,
errors::app_error::{RecorderResult, RecorderError},
errors::app_error::{RecorderError, RecorderResult},
};
pub const SEED_SUBSCRIBER: &str = "konobangu";
@@ -21,9 +21,9 @@ pub struct SubscriberBangumiConfig {
#[sea_orm(table_name = "subscribers")]
pub struct Model {
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub created_at: DateTime,
pub created_at: DateTimeUtc,
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub updated_at: DateTime,
pub updated_at: DateTimeUtc,
#[sea_orm(primary_key)]
pub id: i32,
pub display_name: String,

View File

@@ -44,9 +44,9 @@ pub enum SubscriptionCategory {
#[sea_orm(table_name = "subscriptions")]
pub struct Model {
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub created_at: DateTime,
pub created_at: DateTimeUtc,
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub updated_at: DateTime,
pub updated_at: DateTimeUtc,
#[sea_orm(primary_key)]
pub id: i32,
pub display_name: String,