live.umm.gay/wish-server-rs/src/wish/channel_info.rs

27 lines
686 B
Rust

use std::sync::atomic::Ordering;
use axum::{
extract::{Path, State},
http::StatusCode,
response::{IntoResponse, Response},
Json,
};
use serde::Serialize;
use crate::{streams::get_ongoing_stream, util::log_http_error};
#[derive(Serialize)]
struct ChannelInfo {
view_count: u64,
}
pub async fn get_channel_info(Path(channel): Path<String>) -> Response {
let channel = match get_ongoing_stream(&channel).await {
Ok(c) => c,
Err(e) => return log_http_error(StatusCode::INTERNAL_SERVER_ERROR, e),
};
let view_count = channel.viewer_count.load(Ordering::Relaxed);
let info = ChannelInfo { view_count };
Json(info).into_response()
}