My personal site cherry.computer
htmx tailwind axum askama

fix: expand dev code not included in release builds

cherry.computer b05ab140 d4c5b46a

verified
+35 -25
+19 -7
server/src/index.rs
··· 9 9 10 10 #[derive(Deserialize)] 11 11 pub struct IndexOptions { 12 + #[cfg(debug_assertions)] 12 13 #[serde(default)] 13 14 mock: bool, 14 15 } ··· 20 21 } 21 22 22 23 impl RootTemplate { 23 - pub async fn new(apple_music_client: &AppleMusicClient, options: IndexOptions) -> RootTemplate { 24 + pub async fn new( 25 + apple_music_client: &AppleMusicClient, 26 + #[allow(unused_variables)] options: IndexOptions, 27 + ) -> RootTemplate { 28 + #[cfg(debug_assertions)] 24 29 let media = if options.mock { 25 30 mocked_media() 26 31 } else { 27 - let (game, movie, song) = tokio::join!( 28 - backloggd::cached_fetch(), 29 - letterboxd::cached_fetch(), 30 - apple_music::cached_fetch(apple_music_client) 31 - ); 32 - [game, movie, song].into_iter().flatten().collect() 32 + Self::fetch_media(apple_music_client).await 33 33 }; 34 + #[cfg(not(debug_assertions))] 35 + let media = Self::fetch_media(apple_music_client).await; 34 36 35 37 RootTemplate { media } 36 38 } 39 + 40 + async fn fetch_media(apple_music_client: &AppleMusicClient) -> Vec<Media> { 41 + let (game, movie, song) = tokio::join!( 42 + backloggd::cached_fetch(), 43 + letterboxd::cached_fetch(), 44 + apple_music::cached_fetch(apple_music_client) 45 + ); 46 + [game, movie, song].into_iter().flatten().collect() 47 + } 37 48 } 38 49 50 + #[cfg(debug_assertions)] 39 51 fn mocked_media() -> Vec<Media> { 40 52 vec![ 41 53 Media {
+16 -18
server/src/main.rs
··· 36 36 let apple_music_client = Arc::new(AppleMusicClient::new()?); 37 37 let state = AppState { apple_music_client }; 38 38 39 - let app = Router::new() 40 - .route("/", get(render_index_handler)) 41 - .route("/dev/am-auth-flow", get(render_apple_music_auth_flow)) 39 + let app = Router::new().route("/", get(render_index_handler)); 40 + #[cfg(debug_assertions)] 41 + let app = app.route("/dev/am-auth-flow", get(render_apple_music_auth_flow)); 42 + let app = app 42 43 .fallback(get_service(ServeDir::new("."))) 43 44 .with_state(state) 44 45 .layer( ··· 70 71 }) 71 72 } 72 73 73 - async fn render_apple_music_auth_flow(State(state): State<AppState>) -> impl IntoResponse { 74 - #[cfg(not(debug_assertions))] 75 - return StatusCode::NOT_FOUND; 76 - 77 - #[cfg(debug_assertions)] 78 - { 79 - let template = AuthFlowTemplate::new(&state.apple_music_client); 80 - template 81 - .and_then(|template| Ok(template.render()?)) 82 - .map(Html) 83 - .map_err(|err| { 84 - tracing::error!("failed to render Apple Music auth flow: {err:?}"); 85 - StatusCode::INTERNAL_SERVER_ERROR 86 - }) 87 - } 74 + #[cfg(debug_assertions)] 75 + async fn render_apple_music_auth_flow( 76 + #[allow(unused_variables)] State(state): State<AppState>, 77 + ) -> impl IntoResponse { 78 + let template = AuthFlowTemplate::new(&state.apple_music_client); 79 + template 80 + .and_then(|template| Ok(template.render()?)) 81 + .map(Html) 82 + .map_err(|err| { 83 + tracing::error!("failed to render Apple Music auth flow: {err:?}"); 84 + StatusCode::INTERNAL_SERVER_ERROR 85 + }) 88 86 }