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