From bd8adb9f0193f1482ca866b06cf133ff68fd9a8e Mon Sep 17 00:00:00 2001 From: Naz Date: Tue, 29 Jul 2025 13:46:43 +0100 Subject: =?UTF-8?q?=F0=9F=94=A7refactor:=20remove=20types.rs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/index.rs (limited to 'src/index.rs') diff --git a/src/index.rs b/src/index.rs new file mode 100644 index 0000000..e543b1d --- /dev/null +++ b/src/index.rs @@ -0,0 +1,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> { + 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(()) + } +} -- cgit v1.2.3 From 2cef21906b9bd3c2e92925d7c93d3c8053b52ade Mon Sep 17 00:00:00 2001 From: Naz Date: Tue, 29 Jul 2025 16:27:18 +0100 Subject: =?UTF-8?q?=F0=9F=94=A7refactor:=20move=20the=20rest=20of=20the=20?= =?UTF-8?q?indexing=20relating=20logic=20to=20Index?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/index.rs') diff --git a/src/index.rs b/src/index.rs index e543b1d..069068a 100644 --- a/src/index.rs +++ b/src/index.rs @@ -9,6 +9,16 @@ impl Index { pub fn new() -> Self { Self {} } + pub async fn get(&self, appname: &str) -> Result> { + let index_file_path = index_dir().join(format!("{appname}.json")); + let index_file_content = fs::read_to_string(&index_file_path).await?; + let appimage: AppImage = serde_json::from_str(&index_file_content)?; + + Ok(appimage) + } + pub fn exists(&self, executable: &str) -> bool { + index_dir().join(format!("{}.json", &executable)).exists() + } pub async fn add( &self, appimage: &AppImage, @@ -21,6 +31,12 @@ impl Index { let json = serde_json::to_string_pretty(appimage)?; fs::write(index_file, json).await?; + Ok(()) + } + pub async fn remove(&self, appname: &str) -> Result<(), Box> { + let index_file_path = index_dir().join(format!("{appname}.json")); + fs::remove_file(index_file_path).await?; + Ok(()) } } -- cgit v1.2.3