mirror of
https://github.com/clowzed/sero
synced 2024-05-23 09:42:12 +02:00
23 lines
566 B
Rust
23 lines
566 B
Rust
use entity::prelude::*;
|
|
use sea_orm::{ConnectionTrait, DbErr, ModelTrait};
|
|
|
|
use sea_orm::TransactionTrait;
|
|
|
|
pub struct CorsService;
|
|
|
|
impl CorsService {
|
|
#[tracing::instrument(skip(connection))]
|
|
pub async fn check<T: ConnectionTrait + TransactionTrait>(
|
|
subdomain: Subdomain,
|
|
origin: &str,
|
|
connection: &T,
|
|
) -> Result<bool, DbErr> {
|
|
Ok(subdomain
|
|
.find_related(CorsEntity)
|
|
.all(connection)
|
|
.await?
|
|
.iter()
|
|
.any(|origin_model| origin_model.matches(origin)))
|
|
}
|
|
}
|