Fix formatting
This commit is contained in:
@@ -70,7 +70,6 @@ pub async fn run_analysis(storage: Box<dyn crate::storage::DemoStorage>) {
|
||||
use diesel::prelude::*;
|
||||
use diesel_async::RunQueryDsl;
|
||||
|
||||
|
||||
loop {
|
||||
let mut db_con = db_connection().await;
|
||||
|
||||
|
||||
@@ -51,24 +51,30 @@ async fn main() {
|
||||
let mut component_set = tokio::task::JoinSet::new();
|
||||
|
||||
let storage: Box<dyn backend::storage::DemoStorage> = match args.storage {
|
||||
CliStorage::File => Box::new(backend::storage::FileStorage::new(
|
||||
args.upload_folder.clone(),
|
||||
)),
|
||||
CliStorage::S3 => {
|
||||
let credentials = s3::creds::Credentials::from_env_specific(
|
||||
Some("S3_ACCESS_KEY"),
|
||||
Some("S3_SECRET_KEY"),
|
||||
None,
|
||||
None
|
||||
).unwrap();
|
||||
CliStorage::File => Box::new(backend::storage::FileStorage::new(
|
||||
args.upload_folder.clone(),
|
||||
)),
|
||||
CliStorage::S3 => {
|
||||
let credentials = s3::creds::Credentials::from_env_specific(
|
||||
Some("S3_ACCESS_KEY"),
|
||||
Some("S3_SECRET_KEY"),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let region = s3::Region::from_env("S3_REGION", Some("S3_ENDPOINT")).unwrap();
|
||||
let region = s3::Region::from_env("S3_REGION", Some("S3_ENDPOINT")).unwrap();
|
||||
|
||||
let bucket = std::env::var("S3_BUCKET").expect("Need 'S3_BUCKET' for using s3 storage backend");
|
||||
let bucket =
|
||||
std::env::var("S3_BUCKET").expect("Need 'S3_BUCKET' for using s3 storage backend");
|
||||
|
||||
Box::new(backend::storage::S3Storage::new(&bucket, region, credentials))
|
||||
},
|
||||
};
|
||||
Box::new(backend::storage::S3Storage::new(
|
||||
&bucket,
|
||||
region,
|
||||
credentials,
|
||||
))
|
||||
}
|
||||
};
|
||||
|
||||
tracing::info!("Starting modules");
|
||||
if args.api {
|
||||
|
||||
@@ -14,7 +14,13 @@ pub trait DemoStorage: Send + Sync {
|
||||
's: 'f,
|
||||
'own: 'f;
|
||||
|
||||
fn load<'f, 'own>(&'own self, user_id: String, demo_id: String) -> futures::future::BoxFuture<'f, Result<crate::analysis::AnalysisData, String>> where 'own: 'f;
|
||||
fn load<'f, 'own>(
|
||||
&'own self,
|
||||
user_id: String,
|
||||
demo_id: String,
|
||||
) -> futures::future::BoxFuture<'f, Result<crate::analysis::AnalysisData, String>>
|
||||
where
|
||||
'own: 'f;
|
||||
}
|
||||
|
||||
pub struct FileStorage {
|
||||
@@ -46,7 +52,8 @@ impl DemoStorage for FileStorage {
|
||||
stream: futures_util::stream::BoxStream<'s, axum::body::Bytes>,
|
||||
) -> futures::future::BoxFuture<'f, Result<(), String>>
|
||||
where
|
||||
's: 'f,'own: 'f
|
||||
's: 'f,
|
||||
'own: 'f,
|
||||
{
|
||||
let path = self.folder.clone();
|
||||
|
||||
@@ -79,15 +86,26 @@ impl DemoStorage for FileStorage {
|
||||
.boxed()
|
||||
}
|
||||
|
||||
fn load<'f, 'own>(&'own self, user_id: String, demo_id: String) -> futures::future::BoxFuture<'f, Result<crate::analysis::AnalysisData, String>> where 'own: 'f {
|
||||
fn load<'f, 'own>(
|
||||
&'own self,
|
||||
user_id: String,
|
||||
demo_id: String,
|
||||
) -> futures::future::BoxFuture<'f, Result<crate::analysis::AnalysisData, String>>
|
||||
where
|
||||
'own: 'f,
|
||||
{
|
||||
async move {
|
||||
let user_folder = std::path::Path::new(self.folder.as_path()).join(format!("{}/", user_id));
|
||||
let user_folder =
|
||||
std::path::Path::new(self.folder.as_path()).join(format!("{}/", user_id));
|
||||
let demo_file_path = user_folder.join(format!("{}.dem", demo_id));
|
||||
let file = std::fs::File::open(demo_file_path.as_path()).unwrap();
|
||||
let mmap = unsafe { memmap2::MmapOptions::new().map(&file).unwrap() };
|
||||
|
||||
Ok(crate::analysis::AnalysisData::MemMapped(std::sync::Arc::new(mmap)))
|
||||
}.boxed()
|
||||
Ok(crate::analysis::AnalysisData::MemMapped(
|
||||
std::sync::Arc::new(mmap),
|
||||
))
|
||||
}
|
||||
.boxed()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +114,11 @@ pub struct S3Storage {
|
||||
}
|
||||
|
||||
impl S3Storage {
|
||||
pub fn new(bucket_name: &str, region: s3::region::Region, credentials: s3::creds::Credentials) -> Self {
|
||||
pub fn new(
|
||||
bucket_name: &str,
|
||||
region: s3::region::Region,
|
||||
credentials: s3::creds::Credentials,
|
||||
) -> Self {
|
||||
let mut bucket = s3::bucket::Bucket::new(bucket_name, region, credentials).unwrap();
|
||||
bucket.set_path_style();
|
||||
|
||||
@@ -120,9 +142,10 @@ impl DemoStorage for S3Storage {
|
||||
stream: futures_util::stream::BoxStream<'s, axum::body::Bytes>,
|
||||
) -> futures::future::BoxFuture<'f, Result<(), String>>
|
||||
where
|
||||
's: 'f, 'own: 'f {
|
||||
's: 'f,
|
||||
'own: 'f,
|
||||
{
|
||||
async move {
|
||||
|
||||
let path = std::path::PathBuf::new().join(user_id).join(demo_id);
|
||||
let path = path.to_str().unwrap();
|
||||
|
||||
@@ -133,20 +156,34 @@ impl DemoStorage for S3Storage {
|
||||
|
||||
self.bucket.list(String::new(), None).await.unwrap();
|
||||
|
||||
self.bucket.put_object_stream(&mut body_reader, path).await.unwrap();
|
||||
self.bucket
|
||||
.put_object_stream(&mut body_reader, path)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
Ok(())
|
||||
}.boxed()
|
||||
}
|
||||
.boxed()
|
||||
}
|
||||
|
||||
fn load<'f, 'own>(&'own self, user_id: String, demo_id: String) -> futures::future::BoxFuture<'f, Result<crate::analysis::AnalysisData, String>> where 'own: 'f {
|
||||
fn load<'f, 'own>(
|
||||
&'own self,
|
||||
user_id: String,
|
||||
demo_id: String,
|
||||
) -> futures::future::BoxFuture<'f, Result<crate::analysis::AnalysisData, String>>
|
||||
where
|
||||
'own: 'f,
|
||||
{
|
||||
async move {
|
||||
let path = std::path::PathBuf::new().join(user_id).join(demo_id);
|
||||
let path = path.to_str().unwrap();
|
||||
|
||||
let resp = self.bucket.get_object(path).await.unwrap();
|
||||
|
||||
Ok(crate::analysis::AnalysisData::Preloaded(resp.to_vec().into()))
|
||||
}.boxed()
|
||||
Ok(crate::analysis::AnalysisData::Preloaded(
|
||||
resp.to_vec().into(),
|
||||
))
|
||||
}
|
||||
.boxed()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,9 @@ pub fn homepage() -> impl leptos::IntoView {
|
||||
}
|
||||
|
||||
#[leptos::component]
|
||||
fn demo_list(demos: impl SignalGet<Value = Option<Vec<common::BaseDemoInfo>>> + 'static) -> impl leptos::IntoView {
|
||||
fn demo_list(
|
||||
demos: impl SignalGet<Value = Option<Vec<common::BaseDemoInfo>>> + 'static,
|
||||
) -> impl leptos::IntoView {
|
||||
let style = stylers::style! {
|
||||
"DemoList",
|
||||
.list {
|
||||
|
||||
Reference in New Issue
Block a user