diff --git a/backend/src/lib/lib.rs b/backend/src/lib/lib.rs index cf1cf8c..765be8d 100644 --- a/backend/src/lib/lib.rs +++ b/backend/src/lib/lib.rs @@ -2,4 +2,3 @@ pub mod config; pub mod domain; pub mod inbound; pub mod outbound; -pub mod warrens; diff --git a/backend/src/lib/warrens/db.rs b/backend/src/lib/warrens/db.rs deleted file mode 100644 index 8d39692..0000000 --- a/backend/src/lib/warrens/db.rs +++ /dev/null @@ -1,49 +0,0 @@ -use sqlx::{Acquire, PgExecutor, Postgres}; -use uuid::Uuid; - -use crate::Result; - -use super::Warren; - -impl Warren { - pub async fn get<'c, E>(e: E, id: &Uuid) -> Result - where - E: PgExecutor<'c> + Acquire<'c, Database = Postgres>, - { - let warren: Self = sqlx::query_as( - " - SELECT - * - FROM - warrens - WHERE - id = $1 - ", - ) - .bind(id) - .fetch_one(e) - .await?; - - Ok(warren) - } - - pub async fn list<'c, E>(e: E) -> Result> - where - E: PgExecutor<'c> + Acquire<'c, Database = Postgres>, - { - let warren: Vec = sqlx::query_as( - " - SELECT - * - FROM - warrens - LIMIT - 50 - ", - ) - .fetch_all(e) - .await?; - - Ok(warren) - } -} diff --git a/backend/src/lib/warrens/mod.rs b/backend/src/lib/warrens/mod.rs deleted file mode 100644 index 8f0109b..0000000 --- a/backend/src/lib/warrens/mod.rs +++ /dev/null @@ -1,95 +0,0 @@ -/* pub mod db; - -use std::path::PathBuf; - -use serde::Serialize; -use sqlx::prelude::FromRow; -use uuid::Uuid; - -use crate::{ - Result, - fs::{ - DirectoryEntry, FileType, create_dir, delete_dir, delete_file, get_dir_entries, write_file, - }, -}; - -#[derive(Debug, Clone, Serialize, FromRow)] -#[serde(rename_all = "camelCase")] -pub struct Warren { - id: Uuid, - name: String, - #[serde(skip)] - path: String, -} - -impl Warren { - pub fn id(&self) -> &Uuid { - &self.id - } - - pub fn name(&self) -> &str { - &self.name - } - - pub fn path(&self) -> &str { - &self.path - } -} - -impl Warren { - pub async fn read_path( - &self, - serve_path: &str, - path: Option, - ) -> Result> { - let path = build_path(serve_path, &self.path, path.as_deref()); - - get_dir_entries(path).await - } - - pub async fn create_directory(&self, serve_path: &str, path: String) -> Result<()> { - let path = build_path(serve_path, &self.path, Some(&path)); - - create_dir(path).await - } - - pub async fn delete_entry( - &self, - serve_path: &str, - path: String, - file_type: FileType, - ) -> Result<()> { - let path = build_path(serve_path, &self.path, Some(&path)); - - match file_type { - FileType::File => delete_file(path).await, - FileType::Directory => delete_dir(path).await, - } - } - - pub async fn upload( - &self, - serve_path: &str, - rest_path: Option<&str>, - file_name: &str, - data: &[u8], - ) -> Result<()> { - let rest = format!("{}/{file_name}", rest_path.unwrap_or("")); - - let path = build_path(serve_path, &self.path, Some(&rest)); - - write_file(path, data).await - } -} - -fn build_path(serve_path: &str, warren_path: &str, rest_path: Option<&str>) -> PathBuf { - let mut final_path = PathBuf::from(serve_path); - - final_path.push(warren_path.strip_prefix("/").unwrap_or(warren_path)); - - if let Some(ref rest) = rest_path { - final_path.push(rest.strip_prefix("/").unwrap_or(rest)); - } - - final_path -} */