summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/types.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/types.rs b/src/types.rs
index bd903df..5636fe9 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -1,5 +1,8 @@
use serde::Serialize;
use std::path::PathBuf;
+use tokio::fs;
+
+use crate::{index_dir};
#[derive(Debug, Serialize)]
pub struct AppImage {
@@ -18,3 +21,14 @@ pub struct Source {
pub struct SourceMetadata {
pub url: String,
}
+
+impl AppImage {
+ pub async fn save_to_index(&self, appname: &str) -> Result<(), Box<dyn std::error::Error>> {
+ let index_file = &index_dir().join(format!("{appname}.json"));
+
+ let json = serde_json::to_string_pretty(self)?;
+ fs::write(index_file, json).await?;
+
+ Ok(())
+ }
+}