summaryrefslogtreecommitdiff
path: root/src/index.rs
blob: e543b1d64c8be1502b8416fde08d60c200e7a3c0 (plain)
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
use tokio::fs;

use crate::{AppImage, index_dir};

#[derive(Debug, Default)]
pub struct Index {}

impl Index {
    pub fn new() -> Self {
        Self {}
    }
    pub async fn add(
        &self,
        appimage: &AppImage,
        appname: &str,
    ) -> Result<(), Box<dyn std::error::Error>> {
        fs::create_dir_all(&index_dir()).await?;

        let index_file = &index_dir().join(format!("{appname}.json"));

        let json = serde_json::to_string_pretty(appimage)?;
        fs::write(index_file, json).await?;

        Ok(())
    }
}