- merge /api/uptime + /api/version into /api/health and /api/stats - collapse RTMP per-codec dispatch into a single CodecParser path - dedupe STUN attribute walking (ufrag_pair / parse_xor_mapped_address) - dedupe StreamCodec <-> str0m Codec mapping via StreamCodec::from_str0m - dedupe bearer token extraction in WHIP handlers - replace regex charset validation with stdlib checks - flatten one-field wrappers (WebRtcProxyConfig, HttpServerConfig, ServerInfo) - remove SessionCookie extractor (only fed debug logs) - delete dead code: entity ActiveModel helpers, get_stream_session, WebrtcProxy::local_addr, _connected flag, commented-out blocks - drop unused deps: futures, rand, regex, serde_json
94 lines
2.3 KiB
Rust
94 lines
2.3 KiB
Rust
use sea_orm::{Set, entity::prelude::*};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
|
#[sea_orm(table_name = "stream_key")]
|
|
pub struct Model {
|
|
#[sea_orm(primary_key)]
|
|
pub id: i32,
|
|
#[sea_orm(unique)]
|
|
pub key_value: String,
|
|
pub user_id: i32,
|
|
pub label: String,
|
|
pub is_active: bool,
|
|
pub is_unlisted: bool,
|
|
pub password: Option<String>,
|
|
pub custom_id: Option<String>,
|
|
pub created_at: DateTimeUtc,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
pub enum Relation {
|
|
#[sea_orm(has_many = "super::stream_session::Entity")]
|
|
StreamSession,
|
|
#[sea_orm(
|
|
belongs_to = "super::users::Entity",
|
|
from = "Column::UserId",
|
|
to = "super::users::Column::Id"
|
|
)]
|
|
User,
|
|
}
|
|
|
|
impl Related<super::stream_session::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::StreamSession.def()
|
|
}
|
|
}
|
|
|
|
impl Related<super::users::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::User.def()
|
|
}
|
|
}
|
|
|
|
impl ActiveModelBehavior for ActiveModel {}
|
|
|
|
impl Entity {
|
|
pub async fn create(
|
|
db: &DatabaseConnection,
|
|
user_id: i32,
|
|
key_value: String,
|
|
label: String,
|
|
is_unlisted: bool,
|
|
) -> Result<Model, DbErr> {
|
|
ActiveModel {
|
|
user_id: Set(user_id),
|
|
key_value: Set(key_value),
|
|
label: Set(label),
|
|
is_active: Set(false),
|
|
is_unlisted: Set(is_unlisted),
|
|
created_at: Set(chrono::Utc::now()),
|
|
..Default::default()
|
|
}
|
|
.insert(db)
|
|
.await
|
|
}
|
|
|
|
pub async fn find_by_key(
|
|
db: &DatabaseConnection,
|
|
key_value: &str,
|
|
) -> Result<Option<Model>, DbErr> {
|
|
Entity::find()
|
|
.filter(Column::KeyValue.eq(key_value))
|
|
.one(db)
|
|
.await
|
|
}
|
|
|
|
pub async fn find_by_user(db: &DatabaseConnection, user_id: i32) -> Result<Vec<Model>, DbErr> {
|
|
Entity::find()
|
|
.filter(Column::UserId.eq(user_id))
|
|
.all(db)
|
|
.await
|
|
}
|
|
|
|
pub async fn find_by_custom_id(
|
|
db: &DatabaseConnection,
|
|
custom_id: String,
|
|
) -> Result<Option<Model>, DbErr> {
|
|
Entity::find()
|
|
.filter(Column::CustomId.eq(custom_id))
|
|
.one(db)
|
|
.await
|
|
}
|
|
}
|