tangled
alpha
login
or
join now
cherry.computer
/
website
My personal site
cherry.computer
htmx
tailwind
axum
askama
0
fork
atom
overview
issues
pulls
pipelines
fix: expand dev code not included in release builds
cherry.computer
3 months ago
b05ab140
d4c5b46a
verified
This commit was signed with the committer's
known signature
.
cherry.computer
SSH Key Fingerprint:
SHA256:SIA77Ll0IpMb8Xd3RtaGT+PBIGIePhJJg5W2r6Td7cc=
+35
-25
2 changed files
expand all
collapse all
unified
split
server
src
index.rs
main.rs
+19
-7
server/src/index.rs
···
9
9
10
10
#[derive(Deserialize)]
11
11
pub struct IndexOptions {
12
12
+
#[cfg(debug_assertions)]
12
13
#[serde(default)]
13
14
mock: bool,
14
15
}
···
20
21
}
21
22
22
23
impl RootTemplate {
23
23
-
pub async fn new(apple_music_client: &AppleMusicClient, options: IndexOptions) -> RootTemplate {
24
24
+
pub async fn new(
25
25
+
apple_music_client: &AppleMusicClient,
26
26
+
#[allow(unused_variables)] options: IndexOptions,
27
27
+
) -> RootTemplate {
28
28
+
#[cfg(debug_assertions)]
24
29
let media = if options.mock {
25
30
mocked_media()
26
31
} else {
27
27
-
let (game, movie, song) = tokio::join!(
28
28
-
backloggd::cached_fetch(),
29
29
-
letterboxd::cached_fetch(),
30
30
-
apple_music::cached_fetch(apple_music_client)
31
31
-
);
32
32
-
[game, movie, song].into_iter().flatten().collect()
32
32
+
Self::fetch_media(apple_music_client).await
33
33
};
34
34
+
#[cfg(not(debug_assertions))]
35
35
+
let media = Self::fetch_media(apple_music_client).await;
34
36
35
37
RootTemplate { media }
36
38
}
39
39
+
40
40
+
async fn fetch_media(apple_music_client: &AppleMusicClient) -> Vec<Media> {
41
41
+
let (game, movie, song) = tokio::join!(
42
42
+
backloggd::cached_fetch(),
43
43
+
letterboxd::cached_fetch(),
44
44
+
apple_music::cached_fetch(apple_music_client)
45
45
+
);
46
46
+
[game, movie, song].into_iter().flatten().collect()
47
47
+
}
37
48
}
38
49
50
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
39
-
let app = Router::new()
40
40
-
.route("/", get(render_index_handler))
41
41
-
.route("/dev/am-auth-flow", get(render_apple_music_auth_flow))
39
39
+
let app = Router::new().route("/", get(render_index_handler));
40
40
+
#[cfg(debug_assertions)]
41
41
+
let app = app.route("/dev/am-auth-flow", get(render_apple_music_auth_flow));
42
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
73
-
async fn render_apple_music_auth_flow(State(state): State<AppState>) -> impl IntoResponse {
74
74
-
#[cfg(not(debug_assertions))]
75
75
-
return StatusCode::NOT_FOUND;
76
76
-
77
77
-
#[cfg(debug_assertions)]
78
78
-
{
79
79
-
let template = AuthFlowTemplate::new(&state.apple_music_client);
80
80
-
template
81
81
-
.and_then(|template| Ok(template.render()?))
82
82
-
.map(Html)
83
83
-
.map_err(|err| {
84
84
-
tracing::error!("failed to render Apple Music auth flow: {err:?}");
85
85
-
StatusCode::INTERNAL_SERVER_ERROR
86
86
-
})
87
87
-
}
74
74
+
#[cfg(debug_assertions)]
75
75
+
async fn render_apple_music_auth_flow(
76
76
+
#[allow(unused_variables)] State(state): State<AppState>,
77
77
+
) -> impl IntoResponse {
78
78
+
let template = AuthFlowTemplate::new(&state.apple_music_client);
79
79
+
template
80
80
+
.and_then(|template| Ok(template.render()?))
81
81
+
.map(Html)
82
82
+
.map_err(|err| {
83
83
+
tracing::error!("failed to render Apple Music auth flow: {err:?}");
84
84
+
StatusCode::INTERNAL_SERVER_ERROR
85
85
+
})
88
86
}