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");
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 for &(_, path, bytes) in CERTIFICATE_FONTS {
37 file_storage
38 .upload(Path::new(path), bytes.to_vec(), "application/octet-stream")
39 .await?;
40 }
41 file_storage
42 .upload(
43 Path::new("svgs/certificate-background.svg"),
44 CERTIFICATE_BACKGROUND.to_vec(),
45 "application/octet-stream",
46 )
47 .await?;
48 file_storage
49 .upload(
50 Path::new("jpgs/lilo-and-stitch.jpg"),
51 AUTHOR_IMAGE.to_vec(),
52 "application/octet-stream",
53 )
54 .await?;
55 Ok(SeedFileStorageResult {})
56}