char/live.umm.gay

git clone https://git.t4t.associates/char/live.umm.gay

videogame hacker[wish-server-rs] Add endpoint to see view count11496ff

main
686 B26 linesraw
1use std::sync::atomic::Ordering;
2
3use axum::{
4    extract::{Path, State},
5    http::StatusCode,
6    response::{IntoResponse, Response},
7    Json,
8};
9use serde::Serialize;
10
11use crate::{streams::get_ongoing_stream, util::log_http_error};
12
13#[derive(Serialize)]
14struct ChannelInfo {
15    view_count: u64,
16}
17
18pub async fn get_channel_info(Path(channel): Path<String>) -> Response {
19    let channel = match get_ongoing_stream(&channel).await {
20        Ok(c) => c,
21        Err(e) => return log_http_error(StatusCode::INTERNAL_SERVER_ERROR, e),
22    };
23    let view_count = channel.viewer_count.load(Ordering::Relaxed);
24    let info = ChannelInfo { view_count };
25    Json(info).into_response()
26}