Merge pull request #347 from abnvle/feat/share-folder-browsing
This commit is contained in:
@@ -965,6 +965,71 @@ impl FolderRepository for FolderDbRepository {
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
async fn is_folder_in_subtree(
|
||||
&self,
|
||||
candidate_folder_id: &str,
|
||||
root_folder_id: &str,
|
||||
) -> Result<bool, DomainError> {
|
||||
let (Ok(candidate_uuid), Ok(root_uuid)) = (
|
||||
Uuid::parse_str(candidate_folder_id),
|
||||
Uuid::parse_str(root_folder_id),
|
||||
) else {
|
||||
return Ok(false);
|
||||
};
|
||||
|
||||
let exists: bool = sqlx::query_scalar(
|
||||
"SELECT EXISTS (\
|
||||
SELECT 1 \
|
||||
FROM storage.folders c, storage.folders r \
|
||||
WHERE c.id = $1 \
|
||||
AND r.id = $2 \
|
||||
AND c.is_trashed = false \
|
||||
AND r.is_trashed = false \
|
||||
AND c.lpath <@ r.lpath \
|
||||
)",
|
||||
)
|
||||
.bind(candidate_uuid)
|
||||
.bind(root_uuid)
|
||||
.fetch_one(self.pool())
|
||||
.await
|
||||
.map_err(|e| {
|
||||
DomainError::internal_error("FolderDb", format!("is_folder_in_subtree: {e}"))
|
||||
})?;
|
||||
Ok(exists)
|
||||
}
|
||||
|
||||
async fn is_file_in_subtree(
|
||||
&self,
|
||||
file_id: &str,
|
||||
root_folder_id: &str,
|
||||
) -> Result<bool, DomainError> {
|
||||
let (Ok(file_uuid), Ok(root_uuid)) =
|
||||
(Uuid::parse_str(file_id), Uuid::parse_str(root_folder_id))
|
||||
else {
|
||||
return Ok(false);
|
||||
};
|
||||
|
||||
let exists: bool = sqlx::query_scalar(
|
||||
"SELECT EXISTS (\
|
||||
SELECT 1 \
|
||||
FROM storage.files f \
|
||||
JOIN storage.folders parent ON f.folder_id = parent.id \
|
||||
JOIN storage.folders root ON root.id = $2 \
|
||||
WHERE f.id = $1 \
|
||||
AND f.is_trashed = false \
|
||||
AND parent.is_trashed = false \
|
||||
AND root.is_trashed = false \
|
||||
AND parent.lpath <@ root.lpath \
|
||||
)",
|
||||
)
|
||||
.bind(file_uuid)
|
||||
.bind(root_uuid)
|
||||
.fetch_one(self.pool())
|
||||
.await
|
||||
.map_err(|e| DomainError::internal_error("FolderDb", format!("is_file_in_subtree: {e}")))?;
|
||||
Ok(exists)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Extra helpers for blob-storage bootstrap ──
|
||||
|
||||
Reference in New Issue
Block a user