Skip to content

Commit

Permalink
Merge pull request #257 from AppFlowy-IO/hander_large_blob
Browse files Browse the repository at this point in the history
fix: large file test case
  • Loading branch information
speed2exe authored Jan 15, 2024
2 parents 5a35385 + 05c8080 commit 141f682
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 46 deletions.
19 changes: 8 additions & 11 deletions deploy.env
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ GOTRUE_EXTERNAL_DISCORD_ENABLED=false
GOTRUE_EXTERNAL_DISCORD_CLIENT_ID=
GOTRUE_EXTERNAL_DISCORD_SECRET=
GOTRUE_EXTERNAL_DISCORD_REDIRECT_URI=http://your-host/callback

# File Storage
USE_MINIO=true
# MINIO_URL=http://localhost:9000 # change this if you are using a different address for minio
AWS_ACCESS_KEY_ID=minioadmin
AWS_SECRET_ACCESS_KEY=minioadmin
AWS_S3_BUCKET=appflowy
#AWS_REGION=us-east-1
APPFLOWY_S3_USE_MINIO=true
APPFLOWY_S3_MINIO_URL=http://minio:9000 # change this if you are using a different address for minio
APPFLOWY_S3_ACCESS_KEY=minioadmin
APPFLOWY_S3_SECRET_KEY=minioadmin
APPFLOWY_S3_BUCKET=appflowy
#APPFLOWY_S3_REGION=us-east-1

RUST_LOG=info

Expand All @@ -72,9 +73,5 @@ PORTAINER_PASSWORD=password1234
CLOUDFLARE_TUNNEL_TOKEN=

# If you are using a different postgres database, change the following values
# POSTGRES_USER=
# POSTGRES_DB=
# POSTGRES_PASSWORD=
# POSTGRES_HOST=
# GOTRUE_DATABASE_URL=postgres://supabase_auth_admin:$POSTGRES_PASSWORD@$POSTGRES_HOST:5432/$POSTGRES_DB
# GOTRUE_DATABASE_URL=postgres://supabase_auth_admin:root@<host>:<port>/$POSTGRES_DB
# APPFLOWY_DATABASE_URL=postgres://POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:5432/$POSTGRES_DB
13 changes: 7 additions & 6 deletions dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ GOTRUE_EXTERNAL_DISCORD_ENABLED=false
GOTRUE_EXTERNAL_DISCORD_CLIENT_ID=
GOTRUE_EXTERNAL_DISCORD_SECRET=
GOTRUE_EXTERNAL_DISCORD_REDIRECT_URI=http://localhost:9999/callback

# File Storage
USE_MINIO=true
# MINIO_URL=http://localhost:9000 # change this if you are using a different address for minio
AWS_ACCESS_KEY_ID=minioadmin
AWS_SECRET_ACCESS_KEY=minioadmin
AWS_S3_BUCKET=appflowy
#AWS_REGION=us-east-1
APPFLOWY_S3_USE_MINIO=true
APPFLOWY_S3_MINIO_URL=http://localhost:9000 # change this if you are using a different address for minio
APPFLOWY_S3_ACCESS_KEY=minioadmin
APPFLOWY_S3_SECRET_KEY=minioadmin
APPFLOWY_S3_BUCKET=appflowy
#APPFLOWY_S3_REGION=us-east-1

RUST_LOG=info

Expand Down
19 changes: 16 additions & 3 deletions doc/DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,20 @@ with your own in `nginx/ssl/` directory

## 5. FAQ
- How do I use a different `postgres`?
1. You need set `APPFLOWY_DATABASE_URL` to another postgres url.
You also need to set `DATABASE_URL` to use the same postgres database.
The default url is using the postgres in docker compose, in service `appflowy_cloud` and `gotrue` respectively.
2. You would need to run the initialization sql file from `migrations/before` in your hosted postgres.
However it is possible to change the database storage for it. The following steps are listed below.

1. You need set `APPFLOWY_DATABASE_URL` to another postgres url.
```
APPFLOWY_DATABASE_URL=postgres://<postgres_user>:<password>@<host>:<port>/<dbname>
```

2. You also need to set `GOTRUE_DATABASE_URL` to use the same postgres database.
```
GOTRUE_DATABASE_URL=postgres://supabase_auth_admin:root@<host>:<port>/<dbname>
```
- `supabase_auth_admin` and `root` must be kept in sync with the init migration scripts from `migrations/before`.
Currently it's possible to change the password, but probably can't change the username.
- `dbname` for `appflowy_cloud` and `gotrue` must be the same.

3. You would need to run the initialization sql file from `migrations/before` in your hosted postgres.
12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ services:
- APPFLOWY_GOTRUE_EXT_URL=${API_EXTERNAL_URL}
- APPFLOWY_GOTRUE_ADMIN_EMAIL=${GOTRUE_ADMIN_EMAIL}
- APPFLOWY_GOTRUE_ADMIN_PASSWORD=${GOTRUE_ADMIN_PASSWORD}
- APPFLOWY_S3_USE_MINIO=${USE_MINIO}
- APPFLOWY_S3_MINIO_URL=${MINIO_URL:-http://minio:9000}
- APPFLOWY_S3_ACCESS_KEY=${AWS_ACCESS_KEY_ID}
- APPFLOWY_S3_SECRET_KEY=${AWS_SECRET_ACCESS_KEY}
- APPFLOWY_S3_BUCKET=${AWS_S3_BUCKET}
- APPFLOWY_S3_REGION=${AWS_REGION}
- APPFLOWY_S3_USE_MINIO=${APPFLOWY_S3_USE_MINIO}
- APPFLOWY_S3_MINIO_URL=${APPFLOWY_S3_MINIO_URL}
- APPFLOWY_S3_ACCESS_KEY=${APPFLOWY_S3_ACCESS_KEY}
- APPFLOWY_S3_SECRET_KEY=${APPFLOWY_S3_SECRET_KEY}
- APPFLOWY_S3_BUCKET=${APPFLOWY_S3_BUCKET}
- APPFLOWY_S3_REGION=${APPFLOWY_S3_REGION}
build:
context: .
dockerfile: Dockerfile
Expand Down
9 changes: 7 additions & 2 deletions libs/client-api/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use gotrue::params::{AdminUserParams, GenerateLinkParams};
use mime::Mime;
use parking_lot::RwLock;
use realtime_entity::EncodedCollab;
use reqwest::{header, Body};
use reqwest::{header, Body, StatusCode};

use collab_entity::CollabType;
use reqwest::header::HeaderValue;
Expand Down Expand Up @@ -1103,7 +1103,12 @@ impl Client {
.send()
.await?;
log_request_id(&resp);
Ok(())
if resp.status() == StatusCode::PAYLOAD_TOO_LARGE {
return Err(AppResponseError::from(AppError::PayloadTooLarge(
StatusCode::PAYLOAD_TOO_LARGE.to_string(),
)));
}
AppResponse::<()>::from_response(resp).await?.into_error()
}

/// Only expose this method for testing
Expand Down
7 changes: 2 additions & 5 deletions src/api/file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use app_error::AppError;
use chrono::DateTime;
use database::file::{MAX_BLOB_SIZE, MAX_USAGE};
use database::resource_usage::{get_all_workspace_blob_metadata, get_workspace_usage_size};
use database_entity::dto::AFBlobRecord;
use shared_entity::dto::workspace_dto::{BlobMetadata, RepeatedBlobMetaData, WorkspaceSpaceUsage};
use shared_entity::response::{AppResponse, AppResponseError, JsonAppResponse};
use sqlx::types::Uuid;
Expand Down Expand Up @@ -53,7 +52,7 @@ async fn put_blob_handler(
content_type: web::Header<ContentType>,
content_length: web::Header<ContentLength>,
payload: Payload,
) -> Result<JsonAppResponse<AFBlobRecord>> {
) -> Result<JsonAppResponse<()>> {
let (workspace_id, file_id) = path.into_inner();
let content_length = content_length.into_inner().into_inner();
let content_type = content_type.into_inner().to_string();
Expand Down Expand Up @@ -103,9 +102,7 @@ async fn put_blob_handler(
.await
.map_err(AppResponseError::from)?;

let record = AFBlobRecord::new(file_id);
event!(tracing::Level::TRACE, "did put blob: {:?}", record);
Ok(Json(AppResponse::Ok().with_data(record)))
Ok(AppResponse::Ok().into())
}

#[instrument(level = "debug", skip(state), err)]
Expand Down
26 changes: 13 additions & 13 deletions tests/workspace/blob/put_and_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ async fn put_and_get() {
}

// TODO: fix inconsistent behavior due to different error handling with nginx
// #[tokio::test]
// async fn put_giant_file() {
// let (c1, _user1) = generate_unique_registered_user_client().await;
// let workspace_id = workspace_id_from_client(&c1).await;
// let mime = mime::TEXT_PLAIN_UTF_8;
// let file_id = uuid::Uuid::new_v4().to_string();
//
// let url = c1.get_blob_url(&workspace_id, &file_id);
// let data = vec![0; 10 * 1024 * 1024 * 1024];
// let error = c1.put_blob(&url, data, &mime).await.unwrap_err();
//
// assert_eq!(error.code, ErrorCode::PayloadTooLarge);
// }
#[tokio::test]
async fn put_giant_file() {
let (c1, _user1) = generate_unique_registered_user_client().await;
let workspace_id = workspace_id_from_client(&c1).await;
let mime = mime::TEXT_PLAIN_UTF_8;
let file_id = uuid::Uuid::new_v4().to_string();

let url = c1.get_blob_url(&workspace_id, &file_id);
let data = vec![0; 10 * 1024 * 1024 * 1024];
let error = c1.put_blob(&url, data, &mime).await.unwrap_err();

assert_eq!(error.code, ErrorCode::PayloadTooLarge);
}

#[tokio::test]
async fn put_and_put_and_get() {
Expand Down

0 comments on commit 141f682

Please sign in to comment.