headless_lms_server/programs/seed/
seed_file_storage.rs

1use headless_lms_utils::file_store::{FileStore, local_file_store::LocalFileStore};
2use std::path::Path;
3
4const REPOSITORY_EXERCISE_1: &[u8] = include_bytes!("./data/repository-exercise-1.tar.zst");
5const REPOSITORY_EXERCISE_2: &[u8] = include_bytes!("./data/repository-exercise-2.tar.zst");
6const FONT_LATO_REGULAR: &[u8] = include_bytes!("./data/Lato-Regular.ttf");
7const CERTIFICATE_BACKGROUND: &[u8] = include_bytes!("./data/certificate-background.svg");
8const AUTHOR_IMAGE: &[u8] = include_bytes!("./data/lilo-and-stitch.jpg");
9
10#[derive(Clone)]
11pub struct SeedFileStorageResult {}
12
13pub async fn seed_file_storage() -> anyhow::Result<SeedFileStorageResult> {
14    info!("seeding file storage");
15
16    let file_storage = LocalFileStore::new(
17        "uploads".into(),
18        "http://project-331.local/api/v0/files/uploads/".into(),
19    )
20    .expect("Failed to initialize file store");
21
22    file_storage
23        .upload(
24            Path::new("playground-views/repository-exercise-1.tar.zst"),
25            REPOSITORY_EXERCISE_1.to_vec(),
26            "application/octet-stream",
27        )
28        .await?;
29    file_storage
30        .upload(
31            Path::new("playground-views/repository-exercise-2.tar.zst"),
32            REPOSITORY_EXERCISE_2.to_vec(),
33            "application/octet-stream",
34        )
35        .await?;
36    file_storage
37        .upload(
38            Path::new("fonts/lato-regular.ttf"),
39            FONT_LATO_REGULAR.to_vec(),
40            "application/octet-stream",
41        )
42        .await?;
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    Ok(SeedFileStorageResult {})
58}