fix: fix some issues
This commit is contained in:
@@ -2,12 +2,11 @@ use std::{fmt::Debug, ops::Deref, sync::Arc};
|
||||
|
||||
use fetch::{HttpClient, HttpClientTrait};
|
||||
use maplit::hashmap;
|
||||
use sea_orm::DbErr;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sea_orm::{ActiveModelTrait, ActiveValue::Set, DbErr, TryIntoModel};
|
||||
use url::Url;
|
||||
use util::OptDynErr;
|
||||
|
||||
use super::{MikanConfig, constants::MIKAN_ACCOUNT_MANAGE_PAGE_PATH};
|
||||
use super::{MikanConfig, MikanCredentialForm, constants::MIKAN_ACCOUNT_MANAGE_PAGE_PATH};
|
||||
use crate::{
|
||||
app::AppContextTrait,
|
||||
crypto::UserPassCredential,
|
||||
@@ -15,22 +14,6 @@ use crate::{
|
||||
extract::mikan::constants::{MIKAN_LOGIN_PAGE_PATH, MIKAN_LOGIN_PAGE_SEARCH},
|
||||
models::credential_3rd::{self, Credential3rdType},
|
||||
};
|
||||
#[derive(Default, Clone, Deserialize, Serialize)]
|
||||
pub struct MikanCredentialForm {
|
||||
pub password: String,
|
||||
pub username: String,
|
||||
pub user_agent: String,
|
||||
}
|
||||
|
||||
impl Debug for MikanCredentialForm {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("MikanCredentialForm")
|
||||
.field("username", &String::from("[secrecy]"))
|
||||
.field("password", &String::from("[secrecy]"))
|
||||
.field("user_agent", &String::from("[secrecy]"))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MikanClient {
|
||||
@@ -154,6 +137,28 @@ impl MikanClient {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn save_credential(
|
||||
&self,
|
||||
ctx: Arc<dyn AppContextTrait>,
|
||||
subscriber_id: i32,
|
||||
credential_form: MikanCredentialForm,
|
||||
) -> RecorderResult<credential_3rd::Model> {
|
||||
let db = ctx.db();
|
||||
let am = credential_3rd::ActiveModel {
|
||||
username: Set(Some(credential_form.username)),
|
||||
password: Set(Some(credential_form.password)),
|
||||
user_agent: Set(Some(credential_form.user_agent)),
|
||||
credential_type: Set(Credential3rdType::Mikan),
|
||||
subscriber_id: Set(subscriber_id),
|
||||
..Default::default()
|
||||
}
|
||||
.try_encrypt(ctx.clone())
|
||||
.await?;
|
||||
|
||||
let credential: credential_3rd::Model = am.save(db).await?.try_into_model()?;
|
||||
Ok(credential)
|
||||
}
|
||||
|
||||
pub async fn fork_with_credential(
|
||||
&self,
|
||||
ctx: Arc<dyn AppContextTrait>,
|
||||
|
||||
20
apps/recorder/src/extract/mikan/credential.rs
Normal file
20
apps/recorder/src/extract/mikan/credential.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Default, Clone, Deserialize, Serialize)]
|
||||
pub struct MikanCredentialForm {
|
||||
pub password: String,
|
||||
pub username: String,
|
||||
pub user_agent: String,
|
||||
}
|
||||
|
||||
impl Debug for MikanCredentialForm {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("MikanCredentialForm")
|
||||
.field("username", &String::from("[secrecy]"))
|
||||
.field("password", &String::from("[secrecy]"))
|
||||
.field("user_agent", &String::from("[secrecy]"))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,17 @@
|
||||
mod client;
|
||||
mod config;
|
||||
mod constants;
|
||||
mod credential;
|
||||
mod rss;
|
||||
mod web;
|
||||
|
||||
pub use client::{MikanClient, MikanCredentialForm};
|
||||
pub use client::MikanClient;
|
||||
pub use config::MikanConfig;
|
||||
pub use constants::{
|
||||
MIKAN_ACCOUNT_MANAGE_PAGE_PATH, MIKAN_LOGIN_PAGE_PATH, MIKAN_LOGIN_PAGE_SEARCH,
|
||||
MIKAN_POSTER_BUCKET_KEY, MIKAN_UNKNOWN_FANSUB_ID, MIKAN_UNKNOWN_FANSUB_NAME,
|
||||
};
|
||||
pub use credential::MikanCredentialForm;
|
||||
pub use rss::{
|
||||
MikanBangumiIndexRssChannel, MikanBangumiRssChannel, MikanBangumiRssUrlMeta, MikanRssChannel,
|
||||
MikanRssItem, MikanSubscriberAggregationRssUrlMeta, MikanSubscriberStreamRssChannel,
|
||||
|
||||
@@ -704,21 +704,25 @@ mod test {
|
||||
#![allow(unused_variables)]
|
||||
use std::fs;
|
||||
|
||||
use fetch::get_random_ua;
|
||||
use rstest::{fixture, rstest};
|
||||
use tracing::Level;
|
||||
use url::Url;
|
||||
use zune_image::{codecs::ImageFormat, image::Image};
|
||||
|
||||
use super::*;
|
||||
use crate::test_utils::{
|
||||
app::UnitTestAppContext, database::build_testing_database_service,
|
||||
mikan::build_testing_mikan_client, storage::build_testing_storage_service,
|
||||
tracing::try_init_testing_tracing,
|
||||
use crate::{
|
||||
extract::mikan::MikanCredentialForm,
|
||||
test_utils::{
|
||||
app::UnitTestAppContext, crypto::build_testing_crypto_service,
|
||||
database::build_testing_database_service, mikan::build_testing_mikan_client,
|
||||
storage::build_testing_storage_service, tracing::try_init_testing_tracing,
|
||||
},
|
||||
};
|
||||
|
||||
#[fixture]
|
||||
fn before_each() {
|
||||
try_init_testing_tracing(Level::INFO);
|
||||
try_init_testing_tracing(Level::DEBUG);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
@@ -853,7 +857,7 @@ mod test {
|
||||
|
||||
#[rstest]
|
||||
#[test]
|
||||
fn ttest_extract_mikan_bangumi_meta_from_expand_subscribed_fragment(
|
||||
fn test_extract_mikan_bangumi_meta_from_expand_subscribed_fragment(
|
||||
before_each: (),
|
||||
) -> RecorderResult<()> {
|
||||
let origin_poster_src =
|
||||
@@ -934,9 +938,11 @@ mod test {
|
||||
let app_ctx = {
|
||||
let mikan_client = build_testing_mikan_client(mikan_base_url.clone()).await?;
|
||||
let db_service = build_testing_database_service().await?;
|
||||
let crypto_service = build_testing_crypto_service().await?;
|
||||
let app_ctx = UnitTestAppContext::builder()
|
||||
.mikan(mikan_client)
|
||||
.db(db_service)
|
||||
.crypto(crypto_service)
|
||||
.build();
|
||||
|
||||
Arc::new(app_ctx)
|
||||
@@ -944,6 +950,18 @@ mod test {
|
||||
|
||||
let mikan_client = app_ctx.mikan();
|
||||
|
||||
let credential = mikan_client
|
||||
.save_credential(
|
||||
app_ctx.clone(),
|
||||
1,
|
||||
MikanCredentialForm {
|
||||
username: String::from("test_username"),
|
||||
password: String::from("test_password"),
|
||||
user_agent: get_random_ua().to_string(),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
let mikan_season_flow_url =
|
||||
build_mikan_season_flow_url(mikan_base_url, 2025, MikanSeasonStr::Spring);
|
||||
|
||||
@@ -951,7 +969,7 @@ mod test {
|
||||
mikan_client,
|
||||
app_ctx.clone(),
|
||||
mikan_season_flow_url,
|
||||
1,
|
||||
credential.id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user