runarium 0.1.0

Generate animated videos from GPS running/cycling data with real-time statistics
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
use std::{collections::HashMap, env, fs, sync::Arc, time::Instant};

use anyhow::Result;
use axum::{
  extract::{DefaultBodyLimit, Multipart, State},
  http::{header, StatusCode},
  response::{IntoResponse, Json},
  routing::{get, post},
  Router,
};
use runarium::{
  configs::{
    image_config::RouteImageConfig,
    video_config::{
      Color, FileConfig, Font, LapDataConfig, PaceDistConfig, RouteColor,
      RouteScale, RouteVideoConfig,
    },
  },
  generators::{
    route_image::image_route_with_config,
    route_video::progressive_route_with_config,
  },
};
use serde::{Deserialize, Serialize};
use tokio::{fs::File, io::AsyncWriteExt, sync::Mutex};
use uuid::Uuid;

// In-memory storage
type VideoStore = Arc<Mutex<HashMap<String, Vec<u8>>>>;
type ImageStore = Arc<Mutex<HashMap<String, Vec<u8>>>>;
type AppState = (VideoStore, ImageStore);
#[derive(Debug, Serialize)]
struct VideoResponse {
  success: bool,
  message: String,
  download_url: Option<String>,
  video_id: Option<String>,
  generation_time_ms: Option<u128>,
}

#[derive(Debug, Serialize)]
struct ImageResponse {
  success: bool,
  message: String,
  download_url: Option<String>,
  image_id: Option<String>,
  generation_time_ms: Option<u128>,
}

#[derive(Debug, Serialize)]
struct ErrorResponse {
  error: String,
}

#[derive(Debug, Deserialize)]
struct VideoConfigParams {
  // Route scale
  #[serde(default = "default_scale")]
  scale: f64,
  #[serde(default = "default_offset_x")]
  offset_x_percent: f64,

  #[serde(default = "default_offset_y")]
  offset_y_percent: f64,

  // Colors (BGRA format)
  #[serde(default = "default_route_line_color")]
  route_line_color: [f64; 4],
  #[serde(default = "default_current_position_color")]
  current_position_color: [f64; 4],
  #[serde(default = "default_text_color")]
  text_color: [f64; 4],
  #[serde(default = "default_lap_bars_color")]
  lap_bars_color: [f64; 4],

  // Pace/Distance config
  #[serde(default = "default_pace_font_scale")]
  pace_font_scale: f64,
  #[serde(default = "default_pace_thickness")]
  pace_thickness: i32,

  // Lap data config
  #[serde(default = "default_lap_position_x")]
  lap_position_x: f64,
  #[serde(default = "default_lap_position_y")]
  lap_position_y: f64,
  #[serde(default = "default_lap_font_scale")]
  lap_font_scale: f64,
  #[serde(default = "default_lap_thickness")]
  lap_thickness: i32,

  // Display options
  #[serde(default = "default_true")]
  show_bottom_bar: bool,
  #[serde(default = "default_true")]
  show_route: bool,
  #[serde(default = "default_true")]
  show_lap_data: bool,
  #[serde(default = "default_true")]
  show_pace: bool,
  #[serde(default = "default_true")]
  show_distance: bool,
  #[serde(default = "default_true")]
  show_heart_rate: bool,
  #[serde(default = "default_true")]
  show_stride_length: bool,
  #[serde(default = "default_true")]
  show_pace_bars: bool,
}

fn default_scale() -> f64 {
  0.2
}
fn default_offset_x() -> f64 {
  0.1
}
fn default_offset_y() -> f64 {
  0.1
}
fn default_route_line_color() -> [f64; 4] {
  [0.0, 0.0, 255.0, 0.0]
} // Red
fn default_current_position_color() -> [f64; 4] {
  [0.0, 255.0, 0.0, 0.0]
} // Green
fn default_text_color() -> [f64; 4] {
  [255.0, 255.0, 255.0, 0.0]
} // White
fn default_lap_bars_color() -> [f64; 4] {
  [0.0, 165.0, 255.0, 0.0]
} // Orange
fn default_pace_font_scale() -> f64 {
  0.6
}
fn default_pace_thickness() -> i32 {
  2
}
fn default_lap_position_x() -> f64 {
  0.5
}
fn default_lap_position_y() -> f64 {
  0.09
}
fn default_lap_font_scale() -> f64 {
  0.5
}
fn default_lap_thickness() -> i32 {
  1
}
fn default_true() -> bool {
  true
}

// Health check endpoint
async fn health_check() -> &'static str {
  "OK"
}

// Generate video from uploaded files
async fn generate_video(
  State(state): State<AppState>,
  mut multipart: Multipart,
) -> Result<Json<VideoResponse>, (StatusCode, Json<ErrorResponse>)> {
  let store = &state.0; // video store
                        // Generate unique ID for this video
  let video_id = Uuid::new_v4().to_string();

  // Use system temp directory for production compatibility
  let temp_base = env::temp_dir();
  let temp_dir = temp_base.join(format!("runarium_{}", video_id));

  // Create temp directory for processing only
  fs::create_dir_all(&temp_dir).map_err(|e| {
    (
      StatusCode::INTERNAL_SERVER_ERROR,
      Json(ErrorResponse {
        error: format!("Failed to create temp directory: {}", e),
      }),
    )
  })?;

  let mut fit_data = None;
  let mut background_data = None;
  let mut config_data: Option<String> = None;

  // Process uploaded files - keep in memory
  while let Some(field) = multipart.next_field().await.unwrap() {
    let name = field.name().unwrap_or("").to_string();
    let data = field.bytes().await.unwrap();

    match name.as_str() {
      "fit_file" => fit_data = Some(data),
      "background" => background_data = Some(data),
      "config" => {
        config_data = Some(String::from_utf8_lossy(&data).to_string())
      }
      _ => {}
    }
  }

  // Parse config or use defaults
  let config_params: VideoConfigParams = match config_data {
    Some(json_str) => {
      serde_json::from_str(&json_str).unwrap_or_else(|_| VideoConfigParams {
        scale: default_scale(),
        offset_x_percent: default_offset_x(),
        offset_y_percent: default_offset_y(),
        route_line_color: default_route_line_color(),
        current_position_color: default_current_position_color(),
        text_color: default_text_color(),
        lap_bars_color: default_lap_bars_color(),
        pace_font_scale: default_pace_font_scale(),
        pace_thickness: default_pace_thickness(),
        lap_position_x: default_lap_position_x(),
        lap_position_y: default_lap_position_y(),
        lap_font_scale: default_lap_font_scale(),
        lap_thickness: default_lap_thickness(),
        show_bottom_bar: default_true(),
        show_route: default_true(),
        show_lap_data: default_true(),
        show_pace: default_true(),
        show_distance: default_true(),
        show_heart_rate: default_true(),
        show_stride_length: default_true(),
        show_pace_bars: default_true(),
      })
    }
    None => VideoConfigParams {
      scale: default_scale(),
      offset_x_percent: default_offset_x(),
      offset_y_percent: default_offset_y(),
      route_line_color: default_route_line_color(),
      current_position_color: default_current_position_color(),
      text_color: default_text_color(),
      lap_bars_color: default_lap_bars_color(),
      pace_font_scale: default_pace_font_scale(),
      pace_thickness: default_pace_thickness(),
      lap_position_x: default_lap_position_x(),
      lap_position_y: default_lap_position_y(),
      lap_font_scale: default_lap_font_scale(),
      lap_thickness: default_lap_thickness(),
      show_bottom_bar: default_true(),
      show_route: default_true(),
      show_lap_data: default_true(),
      show_pace: default_true(),
      show_distance: default_true(),
      show_heart_rate: default_true(),
      show_stride_length: default_true(),
      show_pace_bars: default_true(),
    },
  };

  // Validate both files are uploaded
  let fit_bytes = fit_data.ok_or((
    StatusCode::BAD_REQUEST,
    Json(ErrorResponse {
      error: "Missing fit_file in request".to_string(),
    }),
  ))?;

  let background_bytes = background_data.ok_or((
    StatusCode::BAD_REQUEST,
    Json(ErrorResponse {
      error: "Missing background image in request".to_string(),
    }),
  ))?;

  // Write files temporarily for processing
  let fit_path = temp_dir.join("data.fit");
  let bg_path = temp_dir.join("background.jpg");
  let output_path = temp_dir.join("output.mp4");

  // Save temporarily
  write_bytes(&fit_path.to_string_lossy(), &fit_bytes)
    .await
    .map_err(|e| {
      (
        StatusCode::INTERNAL_SERVER_ERROR,
        Json(ErrorResponse {
          error: format!("Failed to write temp FIT file: {}", e),
        }),
      )
    })?;

  write_bytes(
    &bg_path.to_string_lossy(),
    &background_bytes,
  )
  .await
  .map_err(|e| {
    (
      StatusCode::INTERNAL_SERVER_ERROR,
      Json(ErrorResponse {
        error: format!("Failed to write temp background: {}", e),
      }),
    )
  })?;

  // Create configuration with temp paths (using params from request)
  let route_scale = RouteScale::new(
    config_params.scale,
    config_params.offset_x_percent,
    config_params.offset_y_percent,
  );

  let colors = RouteColor::new(
    config_params.route_line_color,
    config_params.current_position_color,
    config_params.text_color,
    config_params.lap_bars_color,
  );

  let pace_dist = PaceDistConfig::new(
    config_params.pace_font_scale,
    config_params.pace_thickness,
    Font::Simplex, // font style
    None,          // position (auto-calculated)
    config_params.show_pace,
    config_params.show_distance,
  );

  let lap_data = LapDataConfig::new(
    (
      config_params.lap_position_x,
      config_params.lap_position_y,
    ),
    config_params.lap_font_scale,
    config_params.lap_thickness,
    Font::Simplex, // font style
    Color::White,  // text_color
    config_params.show_heart_rate,
    config_params.show_stride_length,
    config_params.show_pace_bars,
  );

  let file_config = FileConfig::new(
    fit_path.to_string_lossy().to_string(),
    bg_path.to_string_lossy().to_string(),
    output_path.to_string_lossy().to_string(),
  );

  let config = RouteVideoConfig::new(
    route_scale,
    colors,
    pace_dist,
    lap_data,
    file_config,
    config_params.show_bottom_bar,
    config_params.show_route,
    config_params.show_lap_data,
  );

  // Generate video (blocking operation) - track time
  let start_time = Instant::now();
  let video_result =
    tokio::task::spawn_blocking(move || progressive_route_with_config(config))
      .await
      .map_err(|e| {
        let _ = fs::remove_dir_all(&temp_dir);
        (
          StatusCode::INTERNAL_SERVER_ERROR,
          Json(ErrorResponse {
            error: format!("Task execution failed: {}", e),
          }),
        )
      })?;

  match video_result {
    Ok(_) => {
      let generation_time = start_time.elapsed().as_millis() / 1000;

      // Read generated video into memory
      let video_data = fs::read(&output_path).map_err(|e| {
        let _ = fs::remove_dir_all(&temp_dir);
        (
          StatusCode::INTERNAL_SERVER_ERROR,
          Json(ErrorResponse {
            error: format!("Failed to read generated video: {}", e),
          }),
        )
      })?;

      // Store video in memory
      {
        let mut videos = store.lock().await;
        videos.insert(video_id.clone(), video_data);
      }

      // Clean up temp directory immediately
      let _ = fs::remove_dir_all(&temp_dir);

      Ok(Json(VideoResponse {
        success: true,
        message: "Video generated successfully".to_string(),
        download_url: Some(format!("/download-video/{}", video_id)),
        video_id: Some(video_id),
        generation_time_ms: Some(generation_time),
      }))
    }
    Err(e) => {
      // Clean up on error
      let _ = fs::remove_dir_all(&temp_dir);

      Err((
        StatusCode::INTERNAL_SERVER_ERROR,
        Json(ErrorResponse {
          error: format!("Video generation failed: {}", e),
        }),
      ))
    }
  }
}

// Generate image from uploaded files
async fn generate_image(
  State(state): State<AppState>,
  mut multipart: Multipart,
) -> Result<Json<ImageResponse>, (StatusCode, Json<ErrorResponse>)> {
  let store = &state.1; // image store
                        // Generate unique ID for this image
  let image_id = Uuid::new_v4().to_string();

  // Use system temp directory for production compatibility
  let temp_base = env::temp_dir();
  let temp_dir = temp_base.join(format!("runarium_img_{}", image_id));

  // Create temp directory for processing only
  fs::create_dir_all(&temp_dir).map_err(|e| {
    (
      StatusCode::INTERNAL_SERVER_ERROR,
      Json(ErrorResponse {
        error: format!("Failed to create temp directory: {}", e),
      }),
    )
  })?;

  let mut fit_data = None;
  let mut background_data = None;
  let mut config_data: Option<String> = None;

  // Process uploaded files
  while let Some(field) = multipart.next_field().await.unwrap() {
    let name = field.name().unwrap_or("").to_string();
    let data = field.bytes().await.unwrap();

    match name.as_str() {
      "fit_file" => fit_data = Some(data),
      "background" => background_data = Some(data),
      "config" => {
        config_data = Some(String::from_utf8_lossy(&data).to_string())
      }
      _ => {}
    }
  }

  // Parse config or use defaults
  let config_params: VideoConfigParams = match config_data {
    Some(json_str) => {
      serde_json::from_str(&json_str).unwrap_or_else(|_| VideoConfigParams {
        scale: default_scale(),
        offset_x_percent: default_offset_x(),
        offset_y_percent: default_offset_y(),
        route_line_color: default_route_line_color(),
        current_position_color: default_current_position_color(),
        text_color: default_text_color(),
        lap_bars_color: default_lap_bars_color(),
        pace_font_scale: default_pace_font_scale(),
        pace_thickness: default_pace_thickness(),
        lap_position_x: default_lap_position_x(),
        lap_position_y: default_lap_position_y(),
        lap_font_scale: default_lap_font_scale(),
        lap_thickness: default_lap_thickness(),
        show_bottom_bar: default_true(),
        show_route: default_true(),
        show_lap_data: default_true(),
        show_pace: default_true(),
        show_distance: default_true(),
        show_heart_rate: default_true(),
        show_stride_length: default_true(),
        show_pace_bars: default_true(),
      })
    }
    None => VideoConfigParams {
      scale: default_scale(),
      offset_x_percent: default_offset_x(),
      offset_y_percent: default_offset_y(),
      route_line_color: default_route_line_color(),
      current_position_color: default_current_position_color(),
      text_color: default_text_color(),
      lap_bars_color: default_lap_bars_color(),
      pace_font_scale: default_pace_font_scale(),
      pace_thickness: default_pace_thickness(),
      lap_position_x: default_lap_position_x(),
      lap_position_y: default_lap_position_y(),
      lap_font_scale: default_lap_font_scale(),
      lap_thickness: default_lap_thickness(),
      show_bottom_bar: default_true(),
      show_route: default_true(),
      show_lap_data: default_true(),
      show_pace: default_true(),
      show_distance: default_true(),
      show_heart_rate: default_true(),
      show_stride_length: default_true(),
      show_pace_bars: default_true(),
    },
  };

  // Validate both files are uploaded
  let fit_bytes = fit_data.ok_or((
    StatusCode::BAD_REQUEST,
    Json(ErrorResponse {
      error: "Missing fit_file in request".to_string(),
    }),
  ))?;

  let background_bytes = background_data.ok_or((
    StatusCode::BAD_REQUEST,
    Json(ErrorResponse {
      error: "Missing background image in request".to_string(),
    }),
  ))?;

  // Write files temporarily for processing
  let fit_path = temp_dir.join("data.fit");
  let bg_path = temp_dir.join("background.jpg");
  let output_path = temp_dir.join("output.png");

  // Save temporarily
  write_bytes(&fit_path.to_string_lossy(), &fit_bytes)
    .await
    .map_err(|e| {
      (
        StatusCode::INTERNAL_SERVER_ERROR,
        Json(ErrorResponse {
          error: format!("Failed to write temp FIT file: {}", e),
        }),
      )
    })?;

  write_bytes(
    &bg_path.to_string_lossy(),
    &background_bytes,
  )
  .await
  .map_err(|e| {
    (
      StatusCode::INTERNAL_SERVER_ERROR,
      Json(ErrorResponse {
        error: format!("Failed to write temp background: {}", e),
      }),
    )
  })?;

  // Create configuration for image
  let route_scale = RouteScale::new(
    config_params.scale,
    config_params.offset_x_percent,
    config_params.offset_y_percent,
  );

  let colors = RouteColor::new(
    config_params.route_line_color,
    config_params.current_position_color,
    config_params.text_color,
    config_params.lap_bars_color,
  );

  let lap_data = LapDataConfig::new(
    (
      config_params.lap_position_x,
      config_params.lap_position_y,
    ),
    config_params.lap_font_scale,
    config_params.lap_thickness,
    Font::Simplex,
    Color::White,
    config_params.show_heart_rate,
    config_params.show_stride_length,
    config_params.show_pace_bars,
  );

  let file_config = FileConfig::new(
    fit_path.to_string_lossy().to_string(),
    bg_path.to_string_lossy().to_string(),
    output_path.to_string_lossy().to_string(),
  );

  let config = RouteImageConfig::with_lap_data(
    route_scale,
    colors,
    file_config,
    2, // line_thickness
    lap_data,
  );

  // Generate image (blocking operation) - track time
  let start_time = Instant::now();
  let image_result =
    tokio::task::spawn_blocking(move || image_route_with_config(config))
      .await
      .map_err(|e| {
        let _ = fs::remove_dir_all(&temp_dir);
        (
          StatusCode::INTERNAL_SERVER_ERROR,
          Json(ErrorResponse {
            error: format!("Task execution failed: {}", e),
          }),
        )
      })?;

  match image_result {
    Ok(_) => {
      let generation_time = start_time.elapsed().as_millis() / 1000;

      // Read generated image into memory
      let image_data = fs::read(&output_path).map_err(|e| {
        let _ = fs::remove_dir_all(&temp_dir);
        (
          StatusCode::INTERNAL_SERVER_ERROR,
          Json(ErrorResponse {
            error: format!("Failed to read generated image: {}", e),
          }),
        )
      })?;

      // Store image in memory
      {
        let mut images = store.lock().await;
        images.insert(image_id.clone(), image_data);
      }

      // Clean up temp directory immediately
      let _ = fs::remove_dir_all(&temp_dir);

      Ok(Json(ImageResponse {
        success: true,
        message: "Image generated successfully".to_string(),
        download_url: Some(format!("/download-image/{}", image_id)),
        image_id: Some(image_id),
        generation_time_ms: Some(generation_time),
      }))
    }
    Err(e) => {
      // Clean up on error
      let _ = fs::remove_dir_all(&temp_dir);

      Err((
        StatusCode::INTERNAL_SERVER_ERROR,
        Json(ErrorResponse {
          error: format!("Image generation failed: {}", e),
        }),
      ))
    }
  }
}

// Download generated video (one-time download, then remove)
async fn download_video(
  State(state): State<AppState>,
  axum::extract::Path(video_id): axum::extract::Path<String>,
) -> Result<impl IntoResponse, (StatusCode, Json<ErrorResponse>)> {
  let store = &state.0; // video store
                        // Get and remove video from memory in one operation
  let video_data = {
    let mut videos = store.lock().await;
    videos.remove(&video_id)
  };

  match video_data {
    Some(data) => {
      let mut headers = axum::http::HeaderMap::new();
      headers.insert(
        header::CONTENT_TYPE,
        "video/mp4".parse().unwrap(),
      );
      headers.insert(
        header::CONTENT_DISPOSITION,
        format!(
          "attachment; filename=\"route-{}.mp4\"",
          video_id
        )
        .parse()
        .unwrap(),
      );
      Ok((headers, data))
    }
    None => Err((
      StatusCode::NOT_FOUND,
      Json(ErrorResponse {
        error: "Video not found or already downloaded".to_string(),
      }),
    )),
  }
}

// Download generated image (one-time download, then remove)
async fn download_image(
  State(state): State<AppState>,
  axum::extract::Path(image_id): axum::extract::Path<String>,
) -> Result<impl IntoResponse, (StatusCode, Json<ErrorResponse>)> {
  let store = &state.1; // image store
                        // Get and remove image from memory in one operation
  let image_data = {
    let mut images = store.lock().await;
    images.remove(&image_id)
  };

  match image_data {
    Some(data) => {
      let mut headers = axum::http::HeaderMap::new();
      headers.insert(
        header::CONTENT_TYPE,
        "image/png".parse().unwrap(),
      );
      headers.insert(
        header::CONTENT_DISPOSITION,
        format!(
          "attachment; filename=\"route-{}.png\"",
          image_id
        )
        .parse()
        .unwrap(),
      );
      Ok((headers, data))
    }
    None => Err((
      StatusCode::NOT_FOUND,
      Json(ErrorResponse {
        error: "Image not found or already downloaded".to_string(),
      }),
    )),
  }
}

// Helper function to write bytes to file
async fn write_bytes(path: &str, data: &[u8]) -> Result<()> {
  let mut file = File::create(path).await?;
  file.write_all(data).await?;
  file.flush().await?;
  Ok(())
}

#[tokio::main]
async fn main() {
  // In-memory storage
  let video_store: VideoStore = Arc::new(Mutex::new(HashMap::new()));
  let image_store: ImageStore = Arc::new(Mutex::new(HashMap::new()));

  let app = Router::new()
    .route("/", get(health_check))
    .route("/health", get(health_check))
    .route("/generate-video", post(generate_video))
    .route("/generate-image", post(generate_image))
    .route(
      "/download-video/:video_id",
      get(download_video),
    )
    .route(
      "/download-image/:image_id",
      get(download_image),
    )
    .layer(DefaultBodyLimit::max(100 * 1024 * 1024)) // 100MB limit
    .with_state((video_store, image_store));

  let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();

  axum::serve(listener, app).await.unwrap();
}