feat: Migrate to Apache opendal

This commit is contained in:
quexeky
2026-01-25 21:04:03 +11:00
parent 2518d9e023
commit 8c8e9ad4c9
20 changed files with 443 additions and 772 deletions
+9 -17
View File
@@ -2,11 +2,11 @@ use std::path::{Path, PathBuf};
use crate::{
cli::UploadInfo,
commands::configure::config::Config,
commands::upload::{s3::S3, uploadable::Uploadable},
commands::{connect::config::Config, upload::{chunk_reader::ChunkReader, uploadable::OperatorBuilder}},
manifest::generate_manifest,
};
use log::info;
use tokio_util::compat::FuturesAsyncWriteCompatExt;
pub async fn upload(info: &UploadInfo, config: Config) -> anyhow::Result<()> {
let game_id = &info.game_id;
@@ -14,27 +14,19 @@ pub async fn upload(info: &UploadInfo, config: Config) -> anyhow::Result<()> {
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(S3::new(
&config
let operator = match info.upload_style {
crate::cli::UploadStyle::S3 => config
.get_active_s3()
.ok_or(anyhow::Error::msg("Could not get active S3 value"))?,
)?),
.ok_or(anyhow::Error::msg("Could not get active S3 value"))?.build()?,
};
info!("Uploading chunks");
for (id, data) in &manifest.chunks {
info!("Uploading chunk id {id}");
uploader.upload_chunk(PathBuf::from(path), game_id, version_id, id, data).await?;
let mut reader = ChunkReader::new(&path, data);
let mut writer = operator.writer(&format!("{game_id}/{version_id}/{id}")).await?.into_futures_async_write().compat_write();
tokio::io::copy(&mut reader, &mut writer);
}
info!("Finished uploading chunks");
info!("Uploading manifest");
uploader
.upload_manifest(manifest, game_id, version_id)
.await?;
info!("Uploading speedtest");
uploader.upload_speedtest().await?;
Ok(())
}