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