Compare commits

...
2 Commits
Author SHA1 Message Date
doloro a9bd890d16 cargo clippy fix 2026-09-17 18:57:35 +01:00
doloro 21a20b898c added custom url label and is protected fields to catalog listing 2026-09-17 18:57:00 +01:00
4 changed files with 18 additions and 16 deletions
+4 -4
View File
@@ -51,20 +51,20 @@ impl Model {
.await
}
pub async fn get_all_active_sessions(db: &DatabaseConnection) -> Result<Vec<Model>, DbErr> {
Ok(Entity::find()
Entity::find()
.filter(Column::EndedAt.is_null())
.all(db)
.await?)
.await
}
pub async fn get_active_by_stream_key_id(
db: &DatabaseConnection,
stream_key_id: i32,
) -> Result<Option<Model>, DbErr> {
Ok(Entity::find()
Entity::find()
.filter(Column::StreamKeyId.eq(stream_key_id))
.filter(Column::EndedAt.is_null())
.one(db)
.await?)
.await
}
pub async fn clean_unended_streams(db: &DatabaseConnection) -> Result<u64, DbErr> {
+4 -4
View File
@@ -58,18 +58,18 @@ impl Entity {
if let Some(x) = sessions {
Entity::find_by_id(x.id_user).one(db).await
} else {
return Ok(None);
Ok(None)
}
}
pub async fn find_by_username(
db: &DatabaseConnection,
username: String,
) -> Result<Option<Model>, DbErr> {
let user = Entity::find()
Entity::find()
.filter(Column::Username.eq(username))
.one(db)
.await;
user
.await
}
}
+1 -1
View File
@@ -44,7 +44,7 @@ impl AudioProcesser {
pub fn encode(&mut self, frame: AudioFrame) -> Vec<OpusAudioFrame> {
let mut samples: Vec<f32> = frame
.data
.chunks_exact(4)
.as_chunks::<4>().0.iter()
.map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]]))
.collect();
+9 -7
View File
@@ -125,9 +125,11 @@ impl HttpServer {
#[derive(Serialize)]
struct StreamListing {
label: String,
custom_url_label: String,
id: i32,
user: String,
started_at: DateTime<Utc>, //UNIX TIMESTAMP
started_at: DateTime<Utc>,
is_password_protected: bool,
}
#[derive(Deserialize)]
@@ -160,16 +162,14 @@ async fn edit_stream_key(
}
}
// Empty values are allowed (they clear the field).
if let Some(custom_id) = payload.custom_id.as_deref() {
if !custom_id.is_empty() && !valid_charset(custom_id) {
if let Some(custom_id) = payload.custom_id.as_deref()
&& !custom_id.is_empty() && !valid_charset(custom_id) {
return Err(HttpError::BadRequest("invalid custom id".into()));
}
}
if let Some(pwd) = payload.password.as_deref() {
if !pwd.is_empty() && !valid_charset(pwd) {
if let Some(pwd) = payload.password.as_deref()
&& !pwd.is_empty() && !valid_charset(pwd) {
return Err(HttpError::BadRequest("invalid password".into()));
}
}
let stream_key = stream_key::Entity::find_by_id(payload.id)
.one(&state.db)
@@ -252,8 +252,10 @@ async fn catalog_handler(
.map(|x| StreamListing {
id: x.stream_key_id,
label: x.stream_key_label.clone(),
custom_url_label: x.custom_id.clone().unwrap_or_default(),
user: x.stream_key_user.clone(),
started_at: x.started_at,
is_password_protected: x.password.is_some(),
})
.collect::<Vec<_>>();
Ok(Json(catalog))