You've already forked AstralRinth
forked from didirus/AstralRinth
Move descriptions to database, switch to SHA-512 hashes, fix declining invites not working, allow user deletion, fix broken permission checks for many things, security fixes
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use super::{DeleteFileData, FileHost, FileHostingError, UploadFileData};
|
||||
use async_trait::async_trait;
|
||||
use sha2::Digest;
|
||||
|
||||
mod authorization;
|
||||
mod delete;
|
||||
@@ -32,12 +33,15 @@ impl FileHost for BackblazeHost {
|
||||
file_name: &str,
|
||||
file_bytes: Vec<u8>,
|
||||
) -> 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?;
|
||||
Ok(UploadFileData {
|
||||
file_id: upload_data.file_id,
|
||||
file_name: upload_data.file_name,
|
||||
content_length: upload_data.content_length,
|
||||
content_sha512,
|
||||
content_sha1: upload_data.content_sha1,
|
||||
content_md5: upload_data.content_md5,
|
||||
content_type: upload_data.content_type,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::{DeleteFileData, FileHost, FileHostingError, UploadFileData};
|
||||
use async_trait::async_trait;
|
||||
use sha2::Digest;
|
||||
|
||||
pub struct MockHost(());
|
||||
|
||||
@@ -21,12 +22,14 @@ impl FileHost for MockHost {
|
||||
.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));
|
||||
|
||||
std::fs::write(path, &file_bytes)?;
|
||||
Ok(UploadFileData {
|
||||
file_id: String::from("MOCK_FILE_ID"),
|
||||
file_name: file_name.to_string(),
|
||||
content_length: file_bytes.len() as u32,
|
||||
content_sha512,
|
||||
content_sha1,
|
||||
content_md5: None,
|
||||
content_type: content_type.to_string(),
|
||||
|
||||
@@ -32,6 +32,7 @@ pub struct UploadFileData {
|
||||
pub file_id: String,
|
||||
pub file_name: String,
|
||||
pub content_length: u32,
|
||||
pub content_sha512: String,
|
||||
pub content_sha1: String,
|
||||
pub content_md5: Option<String>,
|
||||
pub content_type: String,
|
||||
|
||||
@@ -3,6 +3,7 @@ use async_trait::async_trait;
|
||||
use s3::bucket::Bucket;
|
||||
use s3::creds::Credentials;
|
||||
use s3::region::Region;
|
||||
use sha2::Digest;
|
||||
|
||||
pub struct S3Host {
|
||||
bucket: Bucket,
|
||||
@@ -40,6 +41,7 @@ impl FileHost for S3Host {
|
||||
file_bytes: Vec<u8>,
|
||||
) -> Result<UploadFileData, FileHostingError> {
|
||||
let content_sha1 = sha1::Sha1::from(&file_bytes).hexdigest();
|
||||
let content_sha512 = format!("{:x}", sha2::Sha512::digest(&file_bytes));
|
||||
|
||||
self.bucket
|
||||
.put_object_with_content_type(
|
||||
@@ -49,37 +51,11 @@ impl FileHost for S3Host {
|
||||
)
|
||||
.await?;
|
||||
|
||||
let provider = &*dotenv::var("S3_PROVIDER").unwrap();
|
||||
|
||||
if provider == "do" {
|
||||
reqwest::Client::new()
|
||||
.delete(&*format!(
|
||||
"https://api.digitalocean.com/v2/cdn/endpoints/{}/cache",
|
||||
self.bucket.name
|
||||
))
|
||||
.header(reqwest::header::CONTENT_TYPE, "application/json")
|
||||
.header(
|
||||
reqwest::header::AUTHORIZATION,
|
||||
self.bucket
|
||||
.credentials
|
||||
.secret_key
|
||||
.clone()
|
||||
.unwrap_or_else(|| "".to_string()),
|
||||
)
|
||||
.body(
|
||||
serde_json::json!({
|
||||
"files": vec![file_name],
|
||||
})
|
||||
.to_string(),
|
||||
)
|
||||
.send()
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(UploadFileData {
|
||||
file_id: file_name.to_string(),
|
||||
file_name: file_name.to_string(),
|
||||
content_length: file_bytes.len() as u32,
|
||||
content_sha512,
|
||||
content_sha1,
|
||||
content_md5: None,
|
||||
content_type: content_type.to_string(),
|
||||
|
||||
Reference in New Issue
Block a user