feat: add replay-stream-tasks pattern support

This commit is contained in:
2025-03-08 16:43:00 +08:00
parent e66573b315
commit f94e175082
47 changed files with 989 additions and 318 deletions

View File

@@ -9,7 +9,7 @@ use super::{
service::{AuthServiceTrait, AuthUserInfo},
};
use crate::{
app::AppContext,
app::AppContextTrait,
models::{auth::AuthType, subscribers::SEED_SUBSCRIBER},
};
@@ -64,7 +64,7 @@ pub struct BasicAuthService {
impl AuthServiceTrait for BasicAuthService {
async fn extract_user_info(
&self,
ctx: &AppContext,
ctx: &dyn AppContextTrait,
request: &mut Parts,
) -> Result<AuthUserInfo, AuthError> {
if let Ok(AuthBasic {

View File

@@ -7,18 +7,21 @@ use axum::{
response::{IntoResponse, Response},
};
use crate::{app::AppContext, auth::AuthServiceTrait};
use crate::{app::AppContextTrait, auth::AuthServiceTrait};
pub async fn header_www_authenticate_middleware(
State(ctx): State<Arc<AppContext>>,
State(ctx): State<Arc<dyn AppContextTrait>>,
request: Request,
next: Next,
) -> Response {
let auth_service = &ctx.auth;
let auth_service = ctx.auth();
let (mut parts, body) = request.into_parts();
let mut response = match auth_service.extract_user_info(&ctx, &mut parts).await {
let mut response = match auth_service
.extract_user_info(ctx.as_ref() as &dyn AppContextTrait, &mut parts)
.await
{
Ok(auth_user_info) => {
let mut request = Request::from_parts(parts, body);
request.extensions_mut().insert(auth_user_info);

View File

@@ -23,7 +23,7 @@ use super::{
errors::AuthError,
service::{AuthServiceTrait, AuthUserInfo},
};
use crate::{app::AppContext, errors::RError, fetch::HttpClient, models::auth::AuthType};
use crate::{app::AppContextTrait, errors::RError, fetch::HttpClient, models::auth::AuthType};
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct OidcAuthClaims {
@@ -261,7 +261,7 @@ impl OidcAuthService {
impl AuthServiceTrait for OidcAuthService {
async fn extract_user_info(
&self,
ctx: &AppContext,
ctx: &dyn AppContextTrait,
request: &mut Parts,
) -> Result<AuthUserInfo, AuthError> {
let config = &self.config;

View File

@@ -1,4 +1,4 @@
use std::time::Duration;
use std::{sync::Arc, time::Duration};
use async_trait::async_trait;
use axum::{
@@ -17,7 +17,7 @@ use super::{
oidc::{OidcAuthClaims, OidcAuthService},
};
use crate::{
app::AppContext,
app::AppContextTrait,
fetch::{
HttpClient, HttpClientConfig,
client::{HttpClientCacheBackendConfig, HttpClientCachePresetConfig},
@@ -31,17 +31,17 @@ pub struct AuthUserInfo {
pub auth_type: AuthType,
}
impl FromRequestParts<AppContext> for AuthUserInfo {
impl FromRequestParts<Arc<dyn AppContextTrait>> for AuthUserInfo {
type Rejection = Response;
async fn from_request_parts(
parts: &mut Parts,
state: &AppContext,
state: &Arc<dyn AppContextTrait>,
) -> Result<Self, Self::Rejection> {
let auth_service = &state.auth;
let auth_service = state.auth();
auth_service
.extract_user_info(state, parts)
.extract_user_info(state.as_ref(), parts)
.await
.map_err(|err| err.into_response())
}
@@ -51,7 +51,7 @@ impl FromRequestParts<AppContext> for AuthUserInfo {
pub trait AuthServiceTrait {
async fn extract_user_info(
&self,
ctx: &AppContext,
ctx: &dyn AppContextTrait,
request: &mut Parts,
) -> Result<AuthUserInfo, AuthError>;
fn www_authenticate_header_value(&self) -> Option<HeaderValue>;
@@ -104,7 +104,7 @@ impl AuthService {
impl AuthServiceTrait for AuthService {
async fn extract_user_info(
&self,
ctx: &AppContext,
ctx: &dyn AppContextTrait,
request: &mut Parts,
) -> Result<AuthUserInfo, AuthError> {
match self {