You've already forked AstralRinth
forked from didirus/AstralRinth
* refactor: improve error handling * fix: specify bind address instead of port * fix: remove temporary testing file * fix(errors): change error names to snake_case * refactor(errors): split indexing error types, remove unused errors * feat: add env variable checking at program start This just checks whether the enviroment variables exist and can parse to the given type and gives a warning if they can't. This should prevent cases where the program fails at runtime due to checking an environment variable that doesn't exist.
78 lines
1.9 KiB
Rust
78 lines
1.9 KiB
Rust
use thiserror::Error;
|
|
|
|
mod authorization;
|
|
mod delete;
|
|
mod upload;
|
|
|
|
pub use authorization::authorize_account;
|
|
pub use authorization::get_upload_url;
|
|
pub use authorization::AuthorizationData;
|
|
pub use authorization::AuthorizationPermissions;
|
|
pub use authorization::UploadUrlData;
|
|
|
|
pub use upload::upload_file;
|
|
pub use upload::UploadFileData;
|
|
|
|
pub use delete::delete_file_version;
|
|
pub use delete::DeleteFileData;
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum FileHostingError {
|
|
#[error("Error while accessing the data from backblaze")]
|
|
BackblazeError(#[from] reqwest::Error),
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[actix_rt::test]
|
|
async fn test_authorization() {
|
|
let authorization_data = authorize_account(
|
|
dotenv::var("BACKBLAZE_KEY_ID").unwrap(),
|
|
dotenv::var("BACKBLAZE_KEY").unwrap(),
|
|
)
|
|
.await
|
|
.unwrap();
|
|
|
|
get_upload_url(
|
|
authorization_data,
|
|
dotenv::var("BACKBLAZE_BUCKET_ID").unwrap(),
|
|
)
|
|
.await
|
|
.unwrap();
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn test_file_management() {
|
|
let authorization_data = authorize_account(
|
|
dotenv::var("BACKBLAZE_KEY_ID").unwrap(),
|
|
dotenv::var("BACKBLAZE_KEY").unwrap(),
|
|
)
|
|
.await
|
|
.unwrap();
|
|
let upload_url_data = get_upload_url(
|
|
authorization_data.clone(),
|
|
dotenv::var("BACKBLAZE_BUCKET_ID").unwrap(),
|
|
)
|
|
.await
|
|
.unwrap();
|
|
let upload_data = upload_file(
|
|
upload_url_data,
|
|
"text/plain".to_string(),
|
|
"test.txt".to_string(),
|
|
"test file".to_string().into_bytes(),
|
|
)
|
|
.await
|
|
.unwrap();
|
|
|
|
delete_file_version(
|
|
authorization_data,
|
|
upload_data.file_id,
|
|
upload_data.file_name,
|
|
)
|
|
.await
|
|
.unwrap();
|
|
}
|
|
}
|