You've already forked AstralRinth
forked from didirus/AstralRinth
95339a8338
* fix(mod-creation): fix actix server data & mod creation route * feat(file-host): implement mock file hosting This implements a mock file hosting system backed by the system's filesystem. It mirrors the API of the backblaze integration, but puts the files directly on disk in the path specified by the MOCK_FILE_PATH environment variable (defaults to /tmp/modrinth). The mock file hosting is enabled by default using cargo features to allow people to work on modrinth without access to a valid backblaze account and setup. To enable backblaze, specify the cargo feature "backblaze" when running, ex. `cargo run --features backblaze`. * feat(file-hosting): implement basic backblaze API error handling * fix(mod-creation): fix extension parsing, use base62 ids for paths fix(file-hosting): reduce unnecessary allocations * fix: fix auth with docker mongodb * fix: fix failing checks * fix: remove testing files
91 lines
2.3 KiB
Rust
91 lines
2.3 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 {
|
|
#[cfg(feature = "backblaze")]
|
|
#[error("Error while accessing the data from backblaze")]
|
|
HttpError(#[from] reqwest::Error),
|
|
|
|
#[cfg(feature = "backblaze")]
|
|
#[error("Backblaze error: {0}")]
|
|
BackblazeError(serde_json::Value),
|
|
|
|
#[cfg(not(feature = "backblaze"))]
|
|
#[error("File system error in file hosting: {0}")]
|
|
FileSystemError(#[from] std::io::Error),
|
|
#[cfg(not(feature = "backblaze"))]
|
|
#[error("Invalid Filename")]
|
|
InvalidFilename,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[actix_rt::test]
|
|
async fn test_authorization() {
|
|
println!("{}", dotenv::var("BACKBLAZE_BUCKET_ID").unwrap());
|
|
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",
|
|
"test.txt",
|
|
"test file".to_string().into_bytes(),
|
|
)
|
|
.await
|
|
.unwrap();
|
|
|
|
delete_file_version(
|
|
&authorization_data,
|
|
&upload_data.file_id,
|
|
&upload_data.file_name,
|
|
)
|
|
.await
|
|
.unwrap();
|
|
}
|
|
}
|