feat: add channel ordering
This commit is contained in:
parent
bcb82d0f46
commit
d8541b2eea
7 changed files with 74 additions and 15 deletions
24
src/utils.rs
24
src/utils.rs
|
@ -9,7 +9,7 @@ use hex::encode;
|
|||
use redis::RedisError;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{Data, error::Error};
|
||||
use crate::{Data, error::Error, structs::Channel};
|
||||
|
||||
pub fn get_auth_header(headers: &HeaderMap) -> Result<&str, Error> {
|
||||
let auth_token = headers.get(actix_web::http::header::AUTHORIZATION);
|
||||
|
@ -119,6 +119,28 @@ pub fn image_check(icon: BytesMut) -> Result<String, Error> {
|
|||
))
|
||||
}
|
||||
|
||||
pub async fn order_channels(mut channels: Vec<Channel>) -> Result<Vec<Channel>, Error> {
|
||||
let mut ordered = Vec::new();
|
||||
|
||||
// Find head
|
||||
let head_pos = channels
|
||||
.iter()
|
||||
.position(|channel| !channels.iter().any(|i| i.is_above == Some(channel.uuid)));
|
||||
|
||||
if let Some(pos) = head_pos {
|
||||
ordered.push(channels.swap_remove(pos));
|
||||
|
||||
while let Some(next_pos) = channels
|
||||
.iter()
|
||||
.position(|channel| Some(channel.uuid) == ordered.last().unwrap().is_above)
|
||||
{
|
||||
ordered.push(channels.swap_remove(next_pos));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(ordered)
|
||||
}
|
||||
|
||||
impl Data {
|
||||
pub async fn set_cache_key(
|
||||
&self,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue