Skip to content

Commit

Permalink
chore: store blob file status (#1147)
Browse files Browse the repository at this point in the history
* chore: store blob file status

* chore: fmt

* chore: fmt
  • Loading branch information
appflowy authored Jan 10, 2025
1 parent 98f9191 commit ee84464
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 5 deletions.
24 changes: 21 additions & 3 deletions .github/workflows/stress_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,26 @@ jobs:
- name: Install Prerequisites
run: |
brew update
brew install libpq
brew install sqlx-cli
brew install protobuf
if ! brew list libpq &>/dev/null; then
echo "Installing libpq..."
brew install libpq
else
echo "libpq is already installed."
fi
if ! brew list sqlx-cli &>/dev/null; then
echo "Installing sqlx-cli..."
brew install sqlx-cli
else
echo "sqlx-cli is already installed."
fi
if ! brew list protobuf &>/dev/null; then
echo "Installing protobuf..."
brew install protobuf
else
echo "protobuf is already installed."
fi
- name: Replace Values in .env
run: |
Expand All @@ -51,6 +68,7 @@ jobs:

- name: Start Docker Compose Services
run: |
docker compose -f docker-compose-dev.yml down
docker compose -f docker-compose-dev.yml up -d
./script/code_gen.sh
cargo sqlx database create && cargo sqlx migrate run
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions libs/database/src/pg_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,32 @@ pub struct AFCollabMemberRow {
pub permission_id: i64,
}

#[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)]
#[repr(i16)]
pub enum AFBlobStatus {
Ok = 0,
DallEContentPolicyViolation = 1,
}

impl From<i16> for AFBlobStatus {
fn from(value: i16) -> Self {
match value {
0 => AFBlobStatus::Ok,
1 => AFBlobStatus::DallEContentPolicyViolation,
_ => AFBlobStatus::Ok,
}
}
}

#[derive(Debug, FromRow, Serialize, Deserialize)]
pub struct AFBlobMetadataRow {
pub workspace_id: Uuid,
pub file_id: String,
pub file_type: String,
pub file_size: i64,
pub modified_at: DateTime<Utc>,
#[serde(default)]
pub status: i16,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
Expand Down
3 changes: 3 additions & 0 deletions migrations/20250109142738_blob_metadata_add_file_status.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Add migration script here
ALTER TABLE af_blob_metadata
ADD COLUMN status SMALLINT NOT NULL DEFAULT 0;
8 changes: 8 additions & 0 deletions src/api/file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::state::AppState;
use anyhow::anyhow;
use aws_sdk_s3::primitives::ByteStream;
use collab_importer::util::FileId;
use database::pg_row::AFBlobStatus;
use serde::Deserialize;
use shared_entity::dto::file_dto::PutFileResponse;
use shared_entity::dto::workspace_dto::{BlobMetadata, RepeatedBlobMetaData, WorkspaceSpaceUsage};
Expand Down Expand Up @@ -369,6 +370,13 @@ async fn get_blob_by_object_key(
}

let metadata = result.unwrap();
match AFBlobStatus::from(metadata.status) {
AFBlobStatus::DallEContentPolicyViolation => {
return Ok(HttpResponse::UnprocessableEntity().finish());
},
AFBlobStatus::Ok => {},
};

// Check if the file is modified since the last time
if let Some(modified_since) = req
.headers()
Expand Down
4 changes: 2 additions & 2 deletions tests/ai_test/chat_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ async fn get_text_with_image_message_test() {
assert_eq!(workspace_id, workspace_id_url);
assert_eq!(chat_id, chat_id_url);

let mut retries = 3;
let retry_interval = Duration::from_secs(8);
let mut retries = 5;
let retry_interval = Duration::from_secs(10);
let mut last_error = None;

// The image will be generated in the background, so we need to retry until it's available
Expand Down

0 comments on commit ee84464

Please sign in to comment.