You've already forked AstralRinth
forked from didirus/AstralRinth
Switch to Postgres (#39)
* WIP Switch to Postgres * feat(postgres): more work on porting to postgres, now compiles * feat(docker-compose): Changed the docker-compose.yml file to use postgres. * Update docker, documentation, gh actions... * Remove bson dependency * Remove bson import * feat: move mock filehost to trait rather than cargo feature * feat(postgres): transactions for mod creation, multipart refactor * fix: Add Cargo.lock so that sqlx functions * Update sqlx offline build data * fix: Use SQLX_OFFLINE to force sqlx into offline mode for CI * Default release channels * feat(postgres): refactor database models to fit postgres models * fix: Fix sqlx prepare, fix double allocation in indexing * Add dockerfile (#40) Co-authored-by: Charalampos Fanoulis <charalampos.fanoulis@gmail.com> Co-authored-by: Aeledfyr <aeledfyr@gmail.com> Co-authored-by: redblueflame <contact@redblueflame.com> Co-authored-by: Jai A <jai.a@tuta.io> Co-authored-by: Valentin Ricard <redblueflame1@gmail.Com> Co-authored-by: Charalampos Fanoulis <charalampos.fanoulis@gmail.com>
This commit is contained in:
48
src/file_hosting/backblaze/upload.rs
Normal file
48
src/file_hosting/backblaze/upload.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use super::authorization::UploadUrlData;
|
||||
use crate::file_hosting::FileHostingError;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UploadFileData {
|
||||
pub file_id: String,
|
||||
pub file_name: String,
|
||||
pub account_id: String,
|
||||
pub bucket_id: String,
|
||||
pub content_length: u32,
|
||||
pub content_sha1: String,
|
||||
pub content_md5: Option<String>,
|
||||
pub content_type: String,
|
||||
pub upload_timestamp: u64,
|
||||
}
|
||||
|
||||
//Content Types found here: https://www.backblaze.com/b2/docs/content-types.html
|
||||
pub async fn upload_file(
|
||||
url_data: &UploadUrlData,
|
||||
content_type: &str,
|
||||
file_name: &str,
|
||||
file_bytes: Vec<u8>,
|
||||
) -> Result<UploadFileData, FileHostingError> {
|
||||
let response = reqwest::Client::new()
|
||||
.post(&url_data.upload_url)
|
||||
.header(
|
||||
reqwest::header::AUTHORIZATION,
|
||||
&url_data.authorization_token,
|
||||
)
|
||||
.header("X-Bz-File-Name", file_name)
|
||||
.header(reqwest::header::CONTENT_TYPE, content_type)
|
||||
.header(reqwest::header::CONTENT_LENGTH, file_bytes.len())
|
||||
.header(
|
||||
"X-Bz-Content-Sha1",
|
||||
sha1::Sha1::from(&file_bytes).hexdigest(),
|
||||
)
|
||||
.body(file_bytes)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
if response.status().is_success() {
|
||||
Ok(response.json().await?)
|
||||
} else {
|
||||
Err(FileHostingError::BackblazeError(response.json().await?))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user