Skip to content

Commit 141f682

Browse files
authored
Merge pull request #257 from AppFlowy-IO/hander_large_blob
fix: large file test case
2 parents 5a35385 + 05c8080 commit 141f682

File tree

7 files changed

+59
-46
lines changed

7 files changed

+59
-46
lines changed

deploy.env

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ GOTRUE_EXTERNAL_DISCORD_ENABLED=false
5151
GOTRUE_EXTERNAL_DISCORD_CLIENT_ID=
5252
GOTRUE_EXTERNAL_DISCORD_SECRET=
5353
GOTRUE_EXTERNAL_DISCORD_REDIRECT_URI=http://your-host/callback
54+
5455
# File Storage
55-
USE_MINIO=true
56-
# MINIO_URL=http://localhost:9000 # change this if you are using a different address for minio
57-
AWS_ACCESS_KEY_ID=minioadmin
58-
AWS_SECRET_ACCESS_KEY=minioadmin
59-
AWS_S3_BUCKET=appflowy
60-
#AWS_REGION=us-east-1
56+
APPFLOWY_S3_USE_MINIO=true
57+
APPFLOWY_S3_MINIO_URL=http://minio:9000 # change this if you are using a different address for minio
58+
APPFLOWY_S3_ACCESS_KEY=minioadmin
59+
APPFLOWY_S3_SECRET_KEY=minioadmin
60+
APPFLOWY_S3_BUCKET=appflowy
61+
#APPFLOWY_S3_REGION=us-east-1
6162

6263
RUST_LOG=info
6364

@@ -72,9 +73,5 @@ PORTAINER_PASSWORD=password1234
7273
CLOUDFLARE_TUNNEL_TOKEN=
7374

7475
# If you are using a different postgres database, change the following values
75-
# POSTGRES_USER=
76-
# POSTGRES_DB=
77-
# POSTGRES_PASSWORD=
78-
# POSTGRES_HOST=
79-
# GOTRUE_DATABASE_URL=postgres://supabase_auth_admin:$POSTGRES_PASSWORD@$POSTGRES_HOST:5432/$POSTGRES_DB
76+
# GOTRUE_DATABASE_URL=postgres://supabase_auth_admin:root@<host>:<port>/$POSTGRES_DB
8077
# APPFLOWY_DATABASE_URL=postgres://POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:5432/$POSTGRES_DB

dev.env

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ GOTRUE_EXTERNAL_DISCORD_ENABLED=false
5656
GOTRUE_EXTERNAL_DISCORD_CLIENT_ID=
5757
GOTRUE_EXTERNAL_DISCORD_SECRET=
5858
GOTRUE_EXTERNAL_DISCORD_REDIRECT_URI=http://localhost:9999/callback
59+
5960
# File Storage
60-
USE_MINIO=true
61-
# MINIO_URL=http://localhost:9000 # change this if you are using a different address for minio
62-
AWS_ACCESS_KEY_ID=minioadmin
63-
AWS_SECRET_ACCESS_KEY=minioadmin
64-
AWS_S3_BUCKET=appflowy
65-
#AWS_REGION=us-east-1
61+
APPFLOWY_S3_USE_MINIO=true
62+
APPFLOWY_S3_MINIO_URL=http://localhost:9000 # change this if you are using a different address for minio
63+
APPFLOWY_S3_ACCESS_KEY=minioadmin
64+
APPFLOWY_S3_SECRET_KEY=minioadmin
65+
APPFLOWY_S3_BUCKET=appflowy
66+
#APPFLOWY_S3_REGION=us-east-1
6667

6768
RUST_LOG=info
6869

doc/DEPLOYMENT.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,20 @@ with your own in `nginx/ssl/` directory
179179

180180
## 5. FAQ
181181
- How do I use a different `postgres`?
182-
1. You need set `APPFLOWY_DATABASE_URL` to another postgres url.
183-
You also need to set `DATABASE_URL` to use the same postgres database.
184182
The default url is using the postgres in docker compose, in service `appflowy_cloud` and `gotrue` respectively.
185-
2. You would need to run the initialization sql file from `migrations/before` in your hosted postgres.
183+
However it is possible to change the database storage for it. The following steps are listed below.
184+
185+
1. You need set `APPFLOWY_DATABASE_URL` to another postgres url.
186+
```
187+
APPFLOWY_DATABASE_URL=postgres://<postgres_user>:<password>@<host>:<port>/<dbname>
188+
```
189+
190+
2. You also need to set `GOTRUE_DATABASE_URL` to use the same postgres database.
191+
```
192+
GOTRUE_DATABASE_URL=postgres://supabase_auth_admin:root@<host>:<port>/<dbname>
193+
```
194+
- `supabase_auth_admin` and `root` must be kept in sync with the init migration scripts from `migrations/before`.
195+
Currently it's possible to change the password, but probably can't change the username.
196+
- `dbname` for `appflowy_cloud` and `gotrue` must be the same.
197+
198+
3. You would need to run the initialization sql file from `migrations/before` in your hosted postgres.

docker-compose.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ services:
9696
- APPFLOWY_GOTRUE_EXT_URL=${API_EXTERNAL_URL}
9797
- APPFLOWY_GOTRUE_ADMIN_EMAIL=${GOTRUE_ADMIN_EMAIL}
9898
- APPFLOWY_GOTRUE_ADMIN_PASSWORD=${GOTRUE_ADMIN_PASSWORD}
99-
- APPFLOWY_S3_USE_MINIO=${USE_MINIO}
100-
- APPFLOWY_S3_MINIO_URL=${MINIO_URL:-http://minio:9000}
101-
- APPFLOWY_S3_ACCESS_KEY=${AWS_ACCESS_KEY_ID}
102-
- APPFLOWY_S3_SECRET_KEY=${AWS_SECRET_ACCESS_KEY}
103-
- APPFLOWY_S3_BUCKET=${AWS_S3_BUCKET}
104-
- APPFLOWY_S3_REGION=${AWS_REGION}
99+
- APPFLOWY_S3_USE_MINIO=${APPFLOWY_S3_USE_MINIO}
100+
- APPFLOWY_S3_MINIO_URL=${APPFLOWY_S3_MINIO_URL}
101+
- APPFLOWY_S3_ACCESS_KEY=${APPFLOWY_S3_ACCESS_KEY}
102+
- APPFLOWY_S3_SECRET_KEY=${APPFLOWY_S3_SECRET_KEY}
103+
- APPFLOWY_S3_BUCKET=${APPFLOWY_S3_BUCKET}
104+
- APPFLOWY_S3_REGION=${APPFLOWY_S3_REGION}
105105
build:
106106
context: .
107107
dockerfile: Dockerfile

libs/client-api/src/http.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use gotrue::params::{AdminUserParams, GenerateLinkParams};
2525
use mime::Mime;
2626
use parking_lot::RwLock;
2727
use realtime_entity::EncodedCollab;
28-
use reqwest::{header, Body};
28+
use reqwest::{header, Body, StatusCode};
2929

3030
use collab_entity::CollabType;
3131
use reqwest::header::HeaderValue;
@@ -1103,7 +1103,12 @@ impl Client {
11031103
.send()
11041104
.await?;
11051105
log_request_id(&resp);
1106-
Ok(())
1106+
if resp.status() == StatusCode::PAYLOAD_TOO_LARGE {
1107+
return Err(AppResponseError::from(AppError::PayloadTooLarge(
1108+
StatusCode::PAYLOAD_TOO_LARGE.to_string(),
1109+
)));
1110+
}
1111+
AppResponse::<()>::from_response(resp).await?.into_error()
11071112
}
11081113

11091114
/// Only expose this method for testing

src/api/file_storage.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use app_error::AppError;
1313
use chrono::DateTime;
1414
use database::file::{MAX_BLOB_SIZE, MAX_USAGE};
1515
use database::resource_usage::{get_all_workspace_blob_metadata, get_workspace_usage_size};
16-
use database_entity::dto::AFBlobRecord;
1716
use shared_entity::dto::workspace_dto::{BlobMetadata, RepeatedBlobMetaData, WorkspaceSpaceUsage};
1817
use shared_entity::response::{AppResponse, AppResponseError, JsonAppResponse};
1918
use sqlx::types::Uuid;
@@ -53,7 +52,7 @@ async fn put_blob_handler(
5352
content_type: web::Header<ContentType>,
5453
content_length: web::Header<ContentLength>,
5554
payload: Payload,
56-
) -> Result<JsonAppResponse<AFBlobRecord>> {
55+
) -> Result<JsonAppResponse<()>> {
5756
let (workspace_id, file_id) = path.into_inner();
5857
let content_length = content_length.into_inner().into_inner();
5958
let content_type = content_type.into_inner().to_string();
@@ -103,9 +102,7 @@ async fn put_blob_handler(
103102
.await
104103
.map_err(AppResponseError::from)?;
105104

106-
let record = AFBlobRecord::new(file_id);
107-
event!(tracing::Level::TRACE, "did put blob: {:?}", record);
108-
Ok(Json(AppResponse::Ok().with_data(record)))
105+
Ok(AppResponse::Ok().into())
109106
}
110107

111108
#[instrument(level = "debug", skip(state), err)]

tests/workspace/blob/put_and_get.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ async fn put_and_get() {
4242
}
4343

4444
// TODO: fix inconsistent behavior due to different error handling with nginx
45-
// #[tokio::test]
46-
// async fn put_giant_file() {
47-
// let (c1, _user1) = generate_unique_registered_user_client().await;
48-
// let workspace_id = workspace_id_from_client(&c1).await;
49-
// let mime = mime::TEXT_PLAIN_UTF_8;
50-
// let file_id = uuid::Uuid::new_v4().to_string();
51-
//
52-
// let url = c1.get_blob_url(&workspace_id, &file_id);
53-
// let data = vec![0; 10 * 1024 * 1024 * 1024];
54-
// let error = c1.put_blob(&url, data, &mime).await.unwrap_err();
55-
//
56-
// assert_eq!(error.code, ErrorCode::PayloadTooLarge);
57-
// }
45+
#[tokio::test]
46+
async fn put_giant_file() {
47+
let (c1, _user1) = generate_unique_registered_user_client().await;
48+
let workspace_id = workspace_id_from_client(&c1).await;
49+
let mime = mime::TEXT_PLAIN_UTF_8;
50+
let file_id = uuid::Uuid::new_v4().to_string();
51+
52+
let url = c1.get_blob_url(&workspace_id, &file_id);
53+
let data = vec![0; 10 * 1024 * 1024 * 1024];
54+
let error = c1.put_blob(&url, data, &mime).await.unwrap_err();
55+
56+
assert_eq!(error.code, ErrorCode::PayloadTooLarge);
57+
}
5858

5959
#[tokio::test]
6060
async fn put_and_put_and_get() {

0 commit comments

Comments
 (0)