You've already forked AstralRinth
forked from didirus/AstralRinth
Initial shared instances backend (#3800)
* Create base shared instance migration and initial routes * Fix build * Add version uploads * Add permissions field for shared instance users * Actually use permissions field * Add "public" flag to shared instances that allow GETing them without authorization * Add the ability to get and list shared instance versions * Add the ability to delete shared instance versions * Fix build after merge * Secured file hosting (#3784) * Remove Backblaze-specific file-hosting backend * Added S3_USES_PATH_STYLE_BUCKETS * Remove unused file_id parameter from delete_file_version * Add support for separate public and private buckets in labrinth::file_hosting * Rename delete_file_version to delete_file * Add (untested) get_url_for_private_file * Remove url field from shared instance routes * Remove url field from shared instance routes * Use private bucket for shared instance versions * Make S3 environment variables fully separate between public and private buckets * Change file host expiry for shared instances to 180 seconds * Fix lint * Merge shared instance migrations into a single migration * Replace shared instance owners with Ghost instead of deleting the instance
This commit is contained in:
@@ -1,23 +1,17 @@
|
||||
use async_trait::async_trait;
|
||||
use thiserror::Error;
|
||||
|
||||
mod backblaze;
|
||||
mod mock;
|
||||
mod s3_host;
|
||||
|
||||
pub use backblaze::BackblazeHost;
|
||||
use bytes::Bytes;
|
||||
pub use mock::MockHost;
|
||||
pub use s3_host::S3Host;
|
||||
pub use s3_host::{S3BucketConfig, S3Host};
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum FileHostingError {
|
||||
#[error("Error while accessing the data from backblaze")]
|
||||
HttpError(#[from] reqwest::Error),
|
||||
#[error("Backblaze error: {0}")]
|
||||
BackblazeError(serde_json::Value),
|
||||
#[error("S3 error: {0}")]
|
||||
S3Error(String),
|
||||
#[error("S3 error when {0}: {1}")]
|
||||
S3Error(&'static str, s3::error::S3Error),
|
||||
#[error("File system error in file hosting: {0}")]
|
||||
FileSystemError(#[from] std::io::Error),
|
||||
#[error("Invalid Filename")]
|
||||
@@ -26,8 +20,8 @@ pub enum FileHostingError {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct UploadFileData {
|
||||
pub file_id: String,
|
||||
pub file_name: String,
|
||||
pub file_publicity: FileHostPublicity,
|
||||
pub content_length: u32,
|
||||
pub content_sha512: String,
|
||||
pub content_sha1: String,
|
||||
@@ -38,22 +32,34 @@ pub struct UploadFileData {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DeleteFileData {
|
||||
pub file_id: String,
|
||||
pub file_name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum FileHostPublicity {
|
||||
Public,
|
||||
Private,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait FileHost {
|
||||
async fn upload_file(
|
||||
&self,
|
||||
content_type: &str,
|
||||
file_name: &str,
|
||||
file_publicity: FileHostPublicity,
|
||||
file_bytes: Bytes,
|
||||
) -> Result<UploadFileData, FileHostingError>;
|
||||
|
||||
async fn delete_file_version(
|
||||
async fn get_url_for_private_file(
|
||||
&self,
|
||||
file_id: &str,
|
||||
file_name: &str,
|
||||
expiry_secs: u32,
|
||||
) -> Result<String, FileHostingError>;
|
||||
|
||||
async fn delete_file(
|
||||
&self,
|
||||
file_name: &str,
|
||||
file_publicity: FileHostPublicity,
|
||||
) -> Result<DeleteFileData, FileHostingError>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user