feat: Logging
Also initial progress on the upload interface
This commit is contained in:
@@ -67,8 +67,6 @@ pub async fn validate_configuration(url: String, token: String) -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
pub mod configure;
|
||||
pub mod configure;
|
||||
pub mod upload;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
use std::path::Path;
|
||||
|
||||
use crate::{
|
||||
cli::UploadInfo,
|
||||
commands::upload::{uploadable::Uploadable, void::VoidUploadable},
|
||||
manifest::generate_manifest,
|
||||
};
|
||||
use log::info;
|
||||
|
||||
pub async fn upload(info: &UploadInfo) -> anyhow::Result<()> {
|
||||
let game_id = &info.game_id;
|
||||
let path = &info.path;
|
||||
let version_id = &info.version_id;
|
||||
|
||||
let manifest = generate_manifest(&Path::new(path)).await?;
|
||||
let mut uploader: Box<dyn Uploadable> = match info.upload_style {
|
||||
crate::cli::UploadStyle::S3 => Box::new(VoidUploadable::new()),
|
||||
crate::cli::UploadStyle::Nginx => Box::new(VoidUploadable::new()),
|
||||
};
|
||||
info!("Uploading chunks");
|
||||
for (id, data) in &manifest.chunks {
|
||||
info!("Uploading chunk id {id}");
|
||||
uploader.upload_chunk(game_id, version_id, id, data)?;
|
||||
}
|
||||
info!("Finished uploading chunks");
|
||||
|
||||
info!("Uploading manifest");
|
||||
uploader.upload_manifest(manifest, game_id, version_id)?;
|
||||
|
||||
info!("Uploading speedtest");
|
||||
uploader.upload_speedtest(game_id, version_id)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
pub mod interface;
|
||||
pub mod s3;
|
||||
pub mod uploadable;
|
||||
pub mod void;
|
||||
@@ -0,0 +1,28 @@
|
||||
use droplet_rs::manifest::{ChunkData, Manifest};
|
||||
|
||||
use crate::commands::upload::uploadable::Uploadable;
|
||||
|
||||
pub type S3 = aws_sdk_s3::Client;
|
||||
impl Uploadable for S3 {
|
||||
fn upload_chunk(
|
||||
&mut self,
|
||||
id: &String,
|
||||
version: &String,
|
||||
chunk_id: &String,
|
||||
chunk: &ChunkData,
|
||||
) -> anyhow::Result<()> {
|
||||
todo!()
|
||||
}
|
||||
fn upload_speedtest(&mut self, game_id: &String, version_id: &String) -> anyhow::Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn upload_manifest(
|
||||
&mut self,
|
||||
manifest: Manifest,
|
||||
game_id: &String,
|
||||
version_id: &String,
|
||||
) -> anyhow::Result<()> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
use droplet_rs::manifest::{ChunkData, Manifest};
|
||||
|
||||
pub trait Uploadable {
|
||||
fn upload_chunk(
|
||||
&mut self,
|
||||
id: &String,
|
||||
version: &String,
|
||||
chunk_id: &String,
|
||||
chunk: &ChunkData,
|
||||
) -> anyhow::Result<()>;
|
||||
fn upload_speedtest(&mut self, game_id: &String, version_id: &String) -> anyhow::Result<()>;
|
||||
fn upload_manifest(&mut self, manifest: Manifest, game_id: &String, version_id: &String) -> anyhow::Result<()>;
|
||||
}
|
||||
pub enum UploadableConfig {
|
||||
S3 {
|
||||
api_secret: String,
|
||||
api_key_identifier: String,
|
||||
region: String,
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
use droplet_rs::manifest::{ChunkData, Manifest};
|
||||
use log::warn;
|
||||
|
||||
use crate::commands::upload::uploadable::Uploadable;
|
||||
|
||||
pub struct VoidUploadable;
|
||||
impl Uploadable for VoidUploadable {
|
||||
fn upload_chunk(
|
||||
&mut self,
|
||||
_id: &String,
|
||||
_version: &String,
|
||||
_chunk_id: &String,
|
||||
_chunk: &ChunkData,
|
||||
) -> anyhow::Result<()> {
|
||||
warn!("Uploading chunk to VoidUploader");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn upload_speedtest(&mut self, _game_id: &String, _version_id: &String) -> anyhow::Result<()> {
|
||||
warn!("Uploading speedtest to VoidUploader");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn upload_manifest(
|
||||
&mut self,
|
||||
_manifest: Manifest,
|
||||
_game_id: &String,
|
||||
_version_id: &String,
|
||||
) -> anyhow::Result<()> {
|
||||
warn!("Uploading manifest to VoidUploader");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
impl VoidUploadable {
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user