Fix clippy errors + lint, use turbo CI

This commit is contained in:
Jai A
2024-10-18 16:07:35 -07:00
parent 663ab83b08
commit 8dd955563e
186 changed files with 10615 additions and 6433 deletions

View File

@@ -16,10 +16,12 @@ pub struct BackblazeHost {
impl BackblazeHost {
pub async fn new(key_id: &str, key: &str, bucket_id: &str) -> Self {
let authorization_data = authorization::authorize_account(key_id, key).await.unwrap();
let upload_url_data = authorization::get_upload_url(&authorization_data, bucket_id)
.await
.unwrap();
let authorization_data =
authorization::authorize_account(key_id, key).await.unwrap();
let upload_url_data =
authorization::get_upload_url(&authorization_data, bucket_id)
.await
.unwrap();
BackblazeHost {
upload_url_data,
@@ -38,8 +40,13 @@ impl FileHost for BackblazeHost {
) -> Result<UploadFileData, FileHostingError> {
let content_sha512 = format!("{:x}", sha2::Sha512::digest(&file_bytes));
let upload_data =
upload::upload_file(&self.upload_url_data, content_type, file_name, file_bytes).await?;
let upload_data = upload::upload_file(
&self.upload_url_data,
content_type,
file_name,
file_bytes,
)
.await?;
Ok(UploadFileData {
file_id: upload_data.file_id,
file_name: upload_data.file_name,
@@ -74,8 +81,12 @@ impl FileHost for BackblazeHost {
file_id: &str,
file_name: &str,
) -> Result<DeleteFileData, FileHostingError> {
let delete_data =
delete::delete_file_version(&self.authorization_data, file_id, file_name).await?;
let delete_data = delete::delete_file_version(
&self.authorization_data,
file_id,
file_name,
)
.await?;
Ok(DeleteFileData {
file_id: delete_data.file_id,
file_name: delete_data.file_name,
@@ -83,7 +94,9 @@ impl FileHost for BackblazeHost {
}
}
pub async fn process_response<T>(response: Response) -> Result<T, FileHostingError>
pub async fn process_response<T>(
response: Response,
) -> Result<T, FileHostingError>
where
T: for<'de> Deserialize<'de>,
{

View File

@@ -56,7 +56,13 @@ pub async fn get_upload_url(
bucket_id: &str,
) -> Result<UploadUrlData, FileHostingError> {
let response = reqwest::Client::new()
.post(format!("{}/b2api/v2/b2_get_upload_url", authorization_data.api_url).to_string())
.post(
format!(
"{}/b2api/v2/b2_get_upload_url",
authorization_data.api_url
)
.to_string(),
)
.header(reqwest::header::CONTENT_TYPE, "application/json")
.header(
reqwest::header::AUTHORIZATION,

View File

@@ -21,9 +21,12 @@ impl FileHost for MockHost {
file_name: &str,
file_bytes: Bytes,
) -> Result<UploadFileData, FileHostingError> {
let path = std::path::Path::new(&dotenvy::var("MOCK_FILE_PATH").unwrap())
.join(file_name.replace("../", ""));
std::fs::create_dir_all(path.parent().ok_or(FileHostingError::InvalidFilename)?)?;
let path =
std::path::Path::new(&dotenvy::var("MOCK_FILE_PATH").unwrap())
.join(file_name.replace("../", ""));
std::fs::create_dir_all(
path.parent().ok_or(FileHostingError::InvalidFilename)?,
)?;
let content_sha1 = sha1::Sha1::from(&file_bytes).hexdigest();
let content_sha512 = format!("{:x}", sha2::Sha512::digest(&file_bytes));
@@ -45,8 +48,9 @@ impl FileHost for MockHost {
file_id: &str,
file_name: &str,
) -> Result<DeleteFileData, FileHostingError> {
let path = std::path::Path::new(&dotenvy::var("MOCK_FILE_PATH").unwrap())
.join(file_name.replace("../", ""));
let path =
std::path::Path::new(&dotenvy::var("MOCK_FILE_PATH").unwrap())
.join(file_name.replace("../", ""));
if path.exists() {
std::fs::remove_file(path)?;
}

View File

@@ -1,4 +1,6 @@
use crate::file_hosting::{DeleteFileData, FileHost, FileHostingError, UploadFileData};
use crate::file_hosting::{
DeleteFileData, FileHost, FileHostingError, UploadFileData,
};
use async_trait::async_trait;
use bytes::Bytes;
use chrono::Utc;
@@ -31,12 +33,23 @@ impl S3Host {
endpoint: url.to_string(),
}
},
Credentials::new(Some(access_token), Some(secret), None, None, None).map_err(|_| {
FileHostingError::S3Error("Error while creating credentials".to_string())
Credentials::new(
Some(access_token),
Some(secret),
None,
None,
None,
)
.map_err(|_| {
FileHostingError::S3Error(
"Error while creating credentials".to_string(),
)
})?,
)
.map_err(|_| {
FileHostingError::S3Error("Error while creating Bucket instance".to_string())
FileHostingError::S3Error(
"Error while creating Bucket instance".to_string(),
)
})?;
Ok(S3Host { bucket })
@@ -55,10 +68,16 @@ impl FileHost for S3Host {
let content_sha512 = format!("{:x}", sha2::Sha512::digest(&file_bytes));
self.bucket
.put_object_with_content_type(format!("/{file_name}"), &file_bytes, content_type)
.put_object_with_content_type(
format!("/{file_name}"),
&file_bytes,
content_type,
)
.await
.map_err(|_| {
FileHostingError::S3Error("Error while uploading file to S3".to_string())
FileHostingError::S3Error(
"Error while uploading file to S3".to_string(),
)
})?;
Ok(UploadFileData {
@@ -82,7 +101,9 @@ impl FileHost for S3Host {
.delete_object(format!("/{file_name}"))
.await
.map_err(|_| {
FileHostingError::S3Error("Error while deleting file from S3".to_string())
FileHostingError::S3Error(
"Error while deleting file from S3".to_string(),
)
})?;
Ok(DeleteFileData {