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::prelude::*;
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let mut db_con = db_connection().await;
|
let mut db_con = db_connection().await;
|
||||||
|
|
||||||
|
|||||||
@@ -59,15 +59,21 @@ async fn main() {
|
|||||||
Some("S3_ACCESS_KEY"),
|
Some("S3_ACCESS_KEY"),
|
||||||
Some("S3_SECRET_KEY"),
|
Some("S3_SECRET_KEY"),
|
||||||
None,
|
None,
|
||||||
None
|
None,
|
||||||
).unwrap();
|
)
|
||||||
|
.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");
|
tracing::info!("Starting modules");
|
||||||
|
|||||||
@@ -14,7 +14,13 @@ pub trait DemoStorage: Send + Sync {
|
|||||||
's: 'f,
|
's: 'f,
|
||||||
'own: '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 {
|
pub struct FileStorage {
|
||||||
@@ -46,7 +52,8 @@ impl DemoStorage for FileStorage {
|
|||||||
stream: futures_util::stream::BoxStream<'s, axum::body::Bytes>,
|
stream: futures_util::stream::BoxStream<'s, axum::body::Bytes>,
|
||||||
) -> futures::future::BoxFuture<'f, Result<(), String>>
|
) -> futures::future::BoxFuture<'f, Result<(), String>>
|
||||||
where
|
where
|
||||||
's: 'f,'own: 'f
|
's: 'f,
|
||||||
|
'own: 'f,
|
||||||
{
|
{
|
||||||
let path = self.folder.clone();
|
let path = self.folder.clone();
|
||||||
|
|
||||||
@@ -79,15 +86,26 @@ impl DemoStorage for FileStorage {
|
|||||||
.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 {
|
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 demo_file_path = user_folder.join(format!("{}.dem", demo_id));
|
||||||
let file = std::fs::File::open(demo_file_path.as_path()).unwrap();
|
let file = std::fs::File::open(demo_file_path.as_path()).unwrap();
|
||||||
let mmap = unsafe { memmap2::MmapOptions::new().map(&file).unwrap() };
|
let mmap = unsafe { memmap2::MmapOptions::new().map(&file).unwrap() };
|
||||||
|
|
||||||
Ok(crate::analysis::AnalysisData::MemMapped(std::sync::Arc::new(mmap)))
|
Ok(crate::analysis::AnalysisData::MemMapped(
|
||||||
}.boxed()
|
std::sync::Arc::new(mmap),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
.boxed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +114,11 @@ pub struct S3Storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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();
|
let mut bucket = s3::bucket::Bucket::new(bucket_name, region, credentials).unwrap();
|
||||||
bucket.set_path_style();
|
bucket.set_path_style();
|
||||||
|
|
||||||
@@ -120,9 +142,10 @@ impl DemoStorage for S3Storage {
|
|||||||
stream: futures_util::stream::BoxStream<'s, axum::body::Bytes>,
|
stream: futures_util::stream::BoxStream<'s, axum::body::Bytes>,
|
||||||
) -> futures::future::BoxFuture<'f, Result<(), String>>
|
) -> futures::future::BoxFuture<'f, Result<(), String>>
|
||||||
where
|
where
|
||||||
's: 'f, 'own: 'f {
|
's: 'f,
|
||||||
|
'own: 'f,
|
||||||
|
{
|
||||||
async move {
|
async move {
|
||||||
|
|
||||||
let path = std::path::PathBuf::new().join(user_id).join(demo_id);
|
let path = std::path::PathBuf::new().join(user_id).join(demo_id);
|
||||||
let path = path.to_str().unwrap();
|
let path = path.to_str().unwrap();
|
||||||
|
|
||||||
@@ -133,20 +156,34 @@ impl DemoStorage for S3Storage {
|
|||||||
|
|
||||||
self.bucket.list(String::new(), None).await.unwrap();
|
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(())
|
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 {
|
async move {
|
||||||
let path = std::path::PathBuf::new().join(user_id).join(demo_id);
|
let path = std::path::PathBuf::new().join(user_id).join(demo_id);
|
||||||
let path = path.to_str().unwrap();
|
let path = path.to_str().unwrap();
|
||||||
|
|
||||||
let resp = self.bucket.get_object(path).await.unwrap();
|
let resp = self.bucket.get_object(path).await.unwrap();
|
||||||
|
|
||||||
Ok(crate::analysis::AnalysisData::Preloaded(resp.to_vec().into()))
|
Ok(crate::analysis::AnalysisData::Preloaded(
|
||||||
}.boxed()
|
resp.to_vec().into(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
.boxed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,9 @@ pub fn homepage() -> impl leptos::IntoView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[leptos::component]
|
#[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! {
|
let style = stylers::style! {
|
||||||
"DemoList",
|
"DemoList",
|
||||||
.list {
|
.list {
|
||||||
|
|||||||
Reference in New Issue
Block a user