Skip to content

Commit 8ec4ee9

Browse files
committed
feat: response streaming and disable non presigned uploads
1 parent 5fd305d commit 8ec4ee9

7 files changed

Lines changed: 35 additions & 89 deletions

File tree

cspell.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"utoipa",
77
"thiserror",
88
"chrono",
9-
"dotenvy"
9+
"dotenvy",
10+
"dotenv"
1011
]
1112
}

lambdas/http/src/docs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use crate::{
5252
document_box::delete,
5353
document_box::search,
5454
// File routes
55+
file::upload,
5556
file::create_presigned,
5657
file::get_presigned,
5758
file::get,

lambdas/http/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,15 @@ pub struct HttpErrorResponse {
107107
pub enum HttpCommonError {
108108
#[error("internal server error")]
109109
ServerError,
110+
#[error("unsupported endpoint")]
111+
Unsupported,
110112
}
111113

112114
impl HttpError for HttpCommonError {
113115
fn status(&self) -> axum::http::StatusCode {
114116
match self {
115117
HttpCommonError::ServerError => StatusCode::INTERNAL_SERVER_ERROR,
118+
HttpCommonError::Unsupported => StatusCode::NOT_IMPLEMENTED,
116119
}
117120
}
118121
}

lambdas/http/src/main.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::{
22
extensions::max_file_size::MaxFileSizeBytes, middleware::api_key::ApiKeyLayer, routes::router,
3-
service::LambdaService,
43
};
5-
use axum::{Extension, Router, extract::DefaultBodyLimit};
4+
use axum::{Extension, Router};
65
use docbox_core::{
76
aws::{SqsClient, aws_config},
87
events::{EventPublisherFactory, sqs::SqsEventPublisherFactory},
@@ -17,17 +16,16 @@ use docbox_search::{SearchIndexFactory, SearchIndexFactoryConfig};
1716
use docbox_secrets::{SecretManager, SecretsManagerConfig};
1817
use docbox_storage::{StorageLayerFactory, StorageLayerFactoryConfig};
1918
use docbox_web_scraper::{WebsiteMetaService, WebsiteMetaServiceConfig};
20-
use lambda_http::{Error, run, tracing};
19+
use lambda_http::{Error, run_with_streaming_response, tracing};
2120
use std::sync::Arc;
22-
use tower_http::{limit::RequestBodyLimitLayer, trace::TraceLayer};
21+
use tower_http::trace::TraceLayer;
2322

2423
pub mod docs;
2524
mod error;
2625
mod extensions;
2726
mod middleware;
2827
mod models;
2928
mod routes;
30-
mod service;
3129

3230
/// The server version extracted from the Cargo.toml
3331
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
@@ -46,11 +44,11 @@ async fn main() -> Result<(), Error> {
4644
// TODO: Handle
4745
.unwrap();
4846

49-
run(app).await
47+
run_with_streaming_response(app).await
5048
}
5149

5250
// TODO: Needs a db_cache.close_all() cleanup logic when the program exits
53-
async fn app() -> Result<LambdaService<Router>, Box<dyn std::error::Error>> {
51+
async fn app() -> Result<Router, Box<dyn std::error::Error>> {
5452
let max_file_size_bytes = match std::env::var("DOCBOX_MAX_FILE_SIZE_BYTES") {
5553
Ok(value) => value.parse::<i32>()?,
5654
// Default max file size in bytes (100MB)
@@ -124,8 +122,6 @@ async fn app() -> Result<LambdaService<Router>, Box<dyn std::error::Error>> {
124122
.layer(Extension(processing))
125123
.layer(Extension(tenant_cache))
126124
.layer(Extension(MaxFileSizeBytes(max_file_size_bytes)))
127-
.layer(DefaultBodyLimit::disable())
128-
.layer(RequestBodyLimitLayer::new(max_file_size_bytes as usize))
129125
.layer(TraceLayer::new_for_http());
130126

131127
if let Some(api_key) = api_key {
@@ -140,5 +136,5 @@ async fn app() -> Result<LambdaService<Router>, Box<dyn std::error::Error>> {
140136
#[cfg(debug_assertions)]
141137
let app = app.layer(tower_http::cors::CorsLayer::very_permissive());
142138

143-
Ok(LambdaService { inner: app })
139+
Ok(app)
144140
}

lambdas/http/src/routes/file.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@ use std::{str::FromStr, time::Duration};
4444

4545
pub const FILE_TAG: &str = "File";
4646

47+
/// Upload file
48+
///
49+
/// This endpoint is not available in docbox serverless, for serverless
50+
/// environments use presigned file uploads instead
51+
#[utoipa::path(
52+
post,
53+
operation_id = "file_upload",
54+
tag = FILE_TAG,
55+
path = "/box/{scope}/file",
56+
responses(
57+
(status = 501, description = "unsupported endpoint", body = HttpErrorResponse)
58+
),
59+
params(
60+
("scope" = DocumentBoxScope, Path, description = "Scope to create the file within"),
61+
TenantParams,
62+
UserParams
63+
)
64+
)]
65+
pub async fn upload() -> HttpResult<()> {
66+
Err(HttpCommonError::Unsupported.into())
67+
}
68+
4769
/// Create presigned file upload
4870
///
4971
/// Creates a new "presigned" upload, where the file is uploaded

lambdas/http/src/routes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub fn folder_router() -> Router {
9090
/// Routes for /box/:scope/file/
9191
pub fn file_router() -> Router {
9292
Router::new()
93+
.route("/", post(file::upload))
9394
.nest(
9495
"/presigned",
9596
Router::new()

lambdas/http/src/service.rs

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)