headless_lms_server/programs/seed/
seed_file_storage.rs1use super::certificate_fonts_data::CERTIFICATE_FONTS;
2use headless_lms_utils::file_store::{FileStore, local_file_store::LocalFileStore};
3use std::path::Path;
4
5const REPOSITORY_EXERCISE_1: &[u8] = include_bytes!("./data/repository-exercise-1.tar.zst");
6const REPOSITORY_EXERCISE_2: &[u8] = include_bytes!("./data/repository-exercise-2.tar.zst");
7const CERTIFICATE_BACKGROUND: &[u8] = include_bytes!("./data/certificate-background.svg");
8const AUTHOR_IMAGE: &[u8] = include_bytes!("./data/lilo-and-stitch.jpg");
9const CHART_EXAMPLE_DATA: &[u8] = include_bytes!("./data/chart-example-data.json");
11
12#[derive(Clone)]
13pub struct SeedFileStorageResult {}
14
15pub async fn seed_file_storage() -> anyhow::Result<SeedFileStorageResult> {
16 info!("seeding file storage");
17
18 let file_storage = LocalFileStore::new(
19 "uploads".into(),
20 "http://project-331.local/api/v0/files/uploads/".into(),
21 )
22 .expect("Failed to initialize file store");
23
24 file_storage
25 .upload(
26 Path::new("playground-views/repository-exercise-1.tar.zst"),
27 REPOSITORY_EXERCISE_1.to_vec(),
28 "application/octet-stream",
29 )
30 .await?;
31 file_storage
32 .upload(
33 Path::new("playground-views/repository-exercise-2.tar.zst"),
34 REPOSITORY_EXERCISE_2.to_vec(),
35 "application/octet-stream",
36 )
37 .await?;
38 for &(_, path, bytes) in CERTIFICATE_FONTS {
39 file_storage
40 .upload(Path::new(path), bytes.to_vec(), "application/octet-stream")
41 .await?;
42 }
43 file_storage
44 .upload(
45 Path::new("svgs/certificate-background.svg"),
46 CERTIFICATE_BACKGROUND.to_vec(),
47 "application/octet-stream",
48 )
49 .await?;
50 file_storage
51 .upload(
52 Path::new("jpgs/lilo-and-stitch.jpg"),
53 AUTHOR_IMAGE.to_vec(),
54 "application/octet-stream",
55 )
56 .await?;
57 file_storage
58 .upload(
59 Path::new("jsons/chart-example-data.json"),
60 CHART_EXAMPLE_DATA.to_vec(),
61 "application/json",
62 )
63 .await?;
64 Ok(SeedFileStorageResult {})
65}