Skip to content

Commit eda65f4

Browse files
committed
make blocks with no user no missing
1 parent 75e19dc commit eda65f4

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/server/block_handlers.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ pub async fn upload_block_handler(
7070

7171
// Get the username from the extension (set by the authorize middleware)
7272
let username = extension.0;
73+
if username.is_empty() {
74+
log::error!("Username is required but not provided");
75+
return Err(ResponseError::BadRequest("Username is required".to_string()));
76+
}
7377
let user_id = auth::get_user_id_from_token(&*state.db, &username).await?;
7478

7579
// Store the block data in the database
@@ -388,6 +392,10 @@ pub async fn get_user_blocks_handler(
388392

389393
// Get the username from the extension (set by the authorize middleware)
390394
let username = extension.0;
395+
if username.is_empty() {
396+
log::error!("Username is required but not provided");
397+
return Err(ResponseError::BadRequest("Username is required".to_string()));
398+
}
391399
let user_id = auth::get_user_id_from_token(&*state.db, &username).await?;
392400

393401
let all_blocks = match state.db.list_blocks(1, 1).await {

src/server/db/sqlite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl DB for SqlDB {
119119
.await;
120120

121121
// If both block and metadata exist, no need to store again
122-
if block_exists && (metadata_exists || file_hash.is_empty()) {
122+
if block_exists && (metadata_exists || file_hash.is_empty() || user_id == 0) {
123123
return true;
124124
}
125125

src/server/file_handlers.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ pub async fn upload_file_handler(
6464

6565
// Get the username from the extension (set by the authorize middleware)
6666
let username = extension.0;
67+
if username.is_empty() {
68+
log::error!("Username is required but not provided");
69+
return Err(ResponseError::BadRequest("Username is required".to_string()));
70+
}
6771
let user_id = auth::get_user_id_from_token(&*state.db, &username).await?;
6872

6973
// Store each block with a reference to the file

0 commit comments

Comments
 (0)