Skip to content

Commit

Permalink
Order sessions by start time and remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jokler committed Feb 25, 2025
1 parent 63c69f2 commit 5c47ce2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 38 deletions.
27 changes: 2 additions & 25 deletions qw-site/src/account/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ use argon2::{Argon2, PasswordHash, PasswordVerifier};
use askama::Template;
use axum::{
body::{boxed, BoxBody, Empty},
extract::{Extension, Form, FromRequest, Query, RequestParts, TypedHeader},
http::{
header::{REFERER, SET_COOKIE},
HeaderValue, Response, StatusCode, Uri,
},
extract::{Extension, Form, Query, TypedHeader},
http::{header::SET_COOKIE, HeaderValue, Response, StatusCode, Uri},
response::{IntoResponse, Redirect},
};
use cookie::Cookie;
Expand Down Expand Up @@ -117,23 +114,3 @@ WHERE email = $1
Ok(None)
}
}

pub struct ExtractReferer(HeaderValue);

#[async_trait::async_trait]
impl<B> FromRequest<B> for ExtractReferer
where
B: Send,
{
type Rejection = (StatusCode, &'static str);

async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
let referer = req.headers().and_then(|headers| headers.get(REFERER));

if let Some(referer) = referer {
Ok(ExtractReferer(referer.clone()))
} else {
Err((StatusCode::BAD_REQUEST, "`Referer` header is missing"))
}
}
}
2 changes: 1 addition & 1 deletion qw-site/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct AppData {

pub(crate) struct AskamaTemplate<'a, T>(&'a T);

impl<'a, T: askama::Template> IntoResponse for AskamaTemplate<'a, T> {
impl<T: askama::Template> IntoResponse for AskamaTemplate<'_, T> {
fn into_response(self) -> Response<BoxBody> {
use askama::DynTemplate;

Expand Down
14 changes: 2 additions & 12 deletions qw-site/src/stream_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ use tracing::*;

pub struct StreamSession {
pub id: i32,
pub account_id: i32,
pub start: time::OffsetDateTime,
pub stop: Option<time::OffsetDateTime>,
}

async fn insert_bitrates(
Expand Down Expand Up @@ -157,11 +154,12 @@ pub async fn get_stream_sessions(
let sessions = conn
.query(
"
SELECT id, start_time, stop_time FROM stream_session
SELECT id FROM stream_session
WHERE
account_id = $1 AND
start_time >= $2 AND
(stop_time <= $3 OR stop_time IS NULL)
ORDER BY start_time
",
&[&account, &start, &end],
)
Expand All @@ -171,11 +169,6 @@ start_time >= $2 AND
.iter()
.map(|r| StreamSession {
id: r.get::<_, i32>(0),
account_id: account,
start: time::OffsetDateTime::from_unix_timestamp(r.get::<_, i64>(1)).unwrap(),
stop: r
.get::<_, Option<i64>>(2)
.map(|t| time::OffsetDateTime::from_unix_timestamp(t).unwrap()),
})
.collect::<Vec<_>>();

Expand All @@ -184,7 +177,6 @@ start_time >= $2 AND

pub struct ActiveStreamSession {
pub viewer_count: i32,
pub started: time::OffsetDateTime,
pub account_name: String,
}

Expand All @@ -196,7 +188,6 @@ pub async fn get_active_public_stream_sessions(
"
SELECT
stream_session.viewer_count,
stream_session.start_time,
account.name
FROM stream_session
INNER JOIN account ON
Expand All @@ -213,7 +204,6 @@ WHERE
.iter()
.map(|r| ActiveStreamSession {
viewer_count: r.get::<_, i32>(0),
started: time::OffsetDateTime::from_unix_timestamp(r.get::<_, i64>(1)).unwrap(),
account_name: r.get::<_, String>(2),
})
.collect::<Vec<_>>();
Expand Down

0 comments on commit 5c47ce2

Please sign in to comment.