Skip to content

Commit

Permalink
Changed a bit, now it can be compiled at least
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominux committed Jan 5, 2025
1 parent e53b8f9 commit ddf74ee
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
6 changes: 6 additions & 0 deletions pentaract/src/models/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ pub struct FSElement {
pub size: i64,
pub is_file: bool,
}

#[derive(Debug, sqlx::FromRow, Serialize)]
pub struct SearchFSElement {
pub path: String,
pub is_file: bool,
}
18 changes: 15 additions & 3 deletions pentaract/src/repositories/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use uuid::Uuid;
use crate::common::db::errors::map_not_found;
use crate::errors::{PentaractError, PentaractResult};
use crate::models::file_chunks::FileChunk;
use crate::models::files::{DBFSElement, FSElement, File, InFile};
use crate::models::files::{DBFSElement, FSElement, File, InFile, SearchFSElement};

pub const FILES_TABLE: &str = "files";
pub const CHUNKS_TABLE: &str = "file_chunks";
Expand Down Expand Up @@ -255,15 +255,27 @@ impl<'d> FilesRepository<'d> {
search_path: &str,
path: &str,
storage_id: Uuid,
) -> PentaractResult<Vec<File>> {
) -> PentaractResult<Vec<SearchFSElement>> {
sqlx::query_as(
format!("SELECT * FROM {FILES_TABLE} WHERE storage_id = $1 AND path ILIKE $2 || '%' || $3 || '%'").as_str(),
format!(
"SELECT
path,
path LIKE '%/' AS is_file
FROM {FILES_TABLE}
WHERE storage_id = $1 AND path ILIKE $2 || '%' || $3 || '%'
"
)
.as_str(),
)
.bind(storage_id)
.bind(path)
.bind(search_path)
.fetch_all(self.db)
.await
.map_err(|e| {
tracing::error!("{e}");
PentaractError::Unknown
})
}

pub async fn get_file_by_path(&self, path: &str, storage_id: Uuid) -> PentaractResult<File> {
Expand Down
4 changes: 2 additions & 2 deletions pentaract/src/routers/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ impl FilesRouter {
search_path: &str,
) -> Result<Response, (StatusCode, String)> {
FilesService::new(&state.db, state.tx.clone())
.search(path, storage_id, search_path, &user)
.search(storage_id, path, search_path, &user)
.await
.map(|files| files.into_iter().map(|file| file.into()).into_response()(headers, body))
.map(|files| Json(files).into_response())
.map_err(|e| <(StatusCode, String)>::from(e))
}

Expand Down
17 changes: 0 additions & 17 deletions pentaract/src/schemas/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,6 @@ impl InFileSchema {
}
}

#[derive(Serialize)]
pub struct SearchFileSchema {
pub id: Uuid,
pub path: String,
pub size: i64,
}

impl From<File> for SearchFileSchema {
fn from(value: File) -> Self {
Self {
id: value.id,
path: value.path,
size: value.size,
}
}
}

pub const IN_FILE_SCHEMA_FIELDS_AMOUNT: usize = 2;

pub struct InFolderSchema {
Expand Down
4 changes: 2 additions & 2 deletions pentaract/src/services/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
errors::{PentaractError, PentaractResult},
models::{
access::AccessType,
files::{FSElement, File, InFile},
files::{FSElement, File, InFile, SearchFSElement},
},
repositories::{
access::AccessRepository, files::FilesRepository, storage_workers::StorageWorkersRepository,
Expand Down Expand Up @@ -239,7 +239,7 @@ impl<'d> FilesService<'d> {
path: &str,
search_path: &str,
user: &AuthUser,
) -> PentaractResult<Vec<File>> {
) -> PentaractResult<Vec<SearchFSElement>> {
check_access(&self.access_repo, user.id, storage_id, &AccessType::R).await?;

self.repo.search(search_path, path, storage_id).await
Expand Down

0 comments on commit ddf74ee

Please sign in to comment.