Skip to content

Commit 0cfdb6a

Browse files
authored
Merge pull request #121 from threefoldtech/development_blocks_with_no_user_not_missing
blocks with no user not missing
2 parents aadafce + eda65f4 commit 0cfdb6a

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
@@ -66,6 +66,10 @@ pub async fn upload_block_handler(
6666

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

7175
// Store the block data in the database
@@ -423,6 +427,10 @@ pub async fn get_user_blocks_handler(
423427

424428
// Get the username from the extension (set by the authorize middleware)
425429
let username = extension.0;
430+
if username.is_empty() {
431+
log::error!("Username is required but not provided");
432+
return Err(ResponseError::BadRequest("Username is required".to_string()));
433+
}
426434
let user_id = auth::get_user_id_from_token(&*state.db, &username).await?;
427435

428436
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
@@ -60,6 +60,10 @@ pub async fn upload_file_handler(
6060

6161
// Get the username from the extension (set by the authorize middleware)
6262
let username = extension.0;
63+
if username.is_empty() {
64+
log::error!("Username is required but not provided");
65+
return Err(ResponseError::BadRequest("Username is required".to_string()));
66+
}
6367
let user_id = auth::get_user_id_from_token(&*state.db, &username).await?;
6468

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

0 commit comments

Comments
 (0)