list warrens + explore nested folders
This commit is contained in:
27
backend/src/api/warrens/get_warren_path.rs
Normal file
27
backend/src/api/warrens/get_warren_path.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use axum::Json;
|
||||
use axum::extract::{Path, State};
|
||||
use serde::Deserialize;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::Result;
|
||||
use crate::api::AppState;
|
||||
use crate::warrens::Warren;
|
||||
|
||||
use crate::fs::DirectoryEntry;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub(super) struct WarrenRequestPath {
|
||||
warren_id: Uuid,
|
||||
rest: Option<String>,
|
||||
}
|
||||
|
||||
pub(super) async fn route(
|
||||
State(state): State<AppState>,
|
||||
Path(WarrenRequestPath { warren_id, rest }): Path<WarrenRequestPath>,
|
||||
) -> Result<Json<Vec<DirectoryEntry>>> {
|
||||
let warren = Warren::get(state.pool(), &warren_id).await?;
|
||||
|
||||
let entries = warren.read_path(state.serve_dir(), rest).await?;
|
||||
|
||||
Ok(Json(entries))
|
||||
}
|
||||
9
backend/src/api/warrens/list_warrens.rs
Normal file
9
backend/src/api/warrens/list_warrens.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
use axum::{Json, extract::State};
|
||||
|
||||
use crate::{Result, api::AppState, warrens::Warren};
|
||||
|
||||
pub(super) async fn route(State(state): State<AppState>) -> Result<Json<Vec<Warren>>> {
|
||||
let warrens = Warren::list(state.pool()).await?;
|
||||
|
||||
Ok(Json(warrens))
|
||||
}
|
||||
13
backend/src/api/warrens/mod.rs
Normal file
13
backend/src/api/warrens/mod.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
mod get_warren_path;
|
||||
mod list_warrens;
|
||||
|
||||
use axum::routing::get;
|
||||
|
||||
use crate::server::Router;
|
||||
|
||||
pub(super) fn router() -> Router {
|
||||
Router::new()
|
||||
.route("/", get(list_warrens::route))
|
||||
.route("/{warren_id}", get(get_warren_path::route))
|
||||
.route("/{warren_id}/{*rest}", get(get_warren_path::route))
|
||||
}
|
||||
Reference in New Issue
Block a user