Skip to content

Commit

Permalink
fix: several compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lennoxlotl committed Oct 22, 2024
1 parent d3c3449 commit adbcf17
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions api/src/endpoint/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ pub async fn show_file(
config: &State<GlobalConfig>,
) -> UploaderResult<FileShowResponse> {
let mut transaction = database.begin().await.map_err(|_| Error::DatabaseError)?;
let image = find_file_by_id(&mut transaction, &id.to_string())
let file = find_file_by_id(&mut transaction, &id.to_string())
.await
.map_err(|_| Error::FileNotFoundError)?;
let data = bucket.get(&image.bucket_id).await.unwrap();
let data = bucket.get(&file.bucket_id).await.unwrap();
let file_type = &data.content_type.ok_or(Error::FileConvertError)?;
let file_bytes = data
.body
Expand Down
2 changes: 1 addition & 1 deletion api/src/endpoint/v1/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub enum Error {
#[error("Invalid auth key")]
#[uploader(status_code = 403)]
Unauthorized,
#[error("The file image is too large")]
#[error("The file is too large")]
#[uploader(status_code = 403)]
FileTooLargeError,
#[error("The file does not exist")]
Expand Down
6 changes: 3 additions & 3 deletions api/src/endpoint/v1/file/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ pub async fn delete(id: &str, database: PostgresDb, bucket: BucketGuard) -> Uplo
}

/// Deletes a file by its secret id, this prevents unauthorized third parties to
/// delete random image ids
/// delete random file ids
async fn inner_delete(id: &str, database: PostgresDb, bucket: BucketGuard) -> UploaderResult<()> {
let mut transaction = database.begin().await.map_err(|_| Error::DatabaseError)?;

let image = delete_file_by_secret(&mut transaction, &id.to_string())
let file = delete_file_by_secret(&mut transaction, &id.to_string())
.await
.map_err(|_| Error::FileNotFoundError)?;
bucket
.delete(&image.bucket_id.as_str())
.delete(&file.bucket_id.as_str())
.await
.map_err(|_| Error::BucketDeleteError)?;

Expand Down
4 changes: 2 additions & 2 deletions api/src/endpoint/v1/file/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub async fn upload(
}
}

// As we use transactions, if the image upload fails the image will be dropped
// As we use transactions, if the file upload fails the file will be dropped
save_file(
&mut transaction,
&id,
Expand Down Expand Up @@ -118,7 +118,7 @@ pub async fn upload(
// TODO: Make api url configurable
Ok(UploadResponse::new(
format!("{}/{}", config.public_url, &id),
format!("{}/api/v1/image/delete/{}", config.public_url, &secret),
format!("{}/api/v1/file/delete/{}", config.public_url, &secret),
))
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub mod s3;
pub struct GlobalConfig {
// Public server url
public_url: String,
// Length of the file id used for "shwoing" the image
// Length of the file id used for "shwoing" the file
file_id_length: usize,
// Defines a Cache-Control header, time is in seconds
cache_length: Option<usize>,
Expand Down

0 comments on commit adbcf17

Please sign in to comment.