use axum::{
Json,
extract::{Query, State},
http::StatusCode,
response::IntoResponse,
};
use fraiseql_core::db::traits::DatabaseAdapter;
use serde::{Deserialize, Serialize};
use crate::routes::graphql::app_state::AppState;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ObjectEntry {
pub key: String,
pub size: u64,
pub content_type: String,
pub updated_at: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BucketEntry {
pub name: String,
pub object_count: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ObjectListResponse {
pub objects: Vec<ObjectEntry>,
pub total: u64,
pub page: u32,
pub page_size: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BucketListResponse {
pub buckets: Vec<BucketEntry>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct ObjectListQuery {
pub bucket: String,
pub prefix: Option<String>,
#[serde(default = "default_page")]
pub page: u32,
#[serde(default = "default_page_size")]
pub page_size: u32,
}
const fn default_page() -> u32 {
1
}
const fn default_page_size() -> u32 {
50
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PresignRequest {
pub bucket: String,
pub key: String,
pub expires_in_secs: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeleteObjectRequest {
pub bucket: String,
pub key: String,
}
pub async fn list_buckets_handler<A>(State(_state): State<AppState<A>>) -> impl IntoResponse
where
A: DatabaseAdapter + Clone + Send + Sync + 'static,
{
Json(BucketListResponse { buckets: vec![] })
}
pub async fn list_objects_handler<A>(
State(_state): State<AppState<A>>,
Query(_params): Query<ObjectListQuery>,
) -> impl IntoResponse
where
A: DatabaseAdapter + Clone + Send + Sync + 'static,
{
Json(ObjectListResponse {
objects: vec![],
total: 0,
page: 1,
page_size: 50,
})
}
pub async fn presign_handler<A>(
State(_state): State<AppState<A>>,
Json(req): Json<PresignRequest>,
) -> impl IntoResponse
where
A: DatabaseAdapter + Clone + Send + Sync + 'static,
{
(
StatusCode::NOT_IMPLEMENTED,
Json(serde_json::json!({
"error": "Not Implemented",
"message": format!(
"Presign for {}/{} not yet wired",
req.bucket, req.key
)
})),
)
}
pub async fn delete_object_handler<A>(
State(_state): State<AppState<A>>,
Json(req): Json<DeleteObjectRequest>,
) -> impl IntoResponse
where
A: DatabaseAdapter + Clone + Send + Sync + 'static,
{
(
StatusCode::NOT_IMPLEMENTED,
Json(serde_json::json!({
"error": "Not Implemented",
"message": format!(
"Delete {}/{} not yet wired",
req.bucket, req.key
)
})),
)
}