use remi::{Blob, StorageService as _, UploadRequest};
use remi_fs::{Config, StorageService};
use std::{io, path::PathBuf};
use tracing_subscriber::prelude::*;
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), io::Error> {
tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer())
.init();
let config = Config {
directory: PathBuf::from("./data"),
};
let fs = StorageService::with_config(config);
eprintln!("init ./data dir");
fs.init().await?;
eprintln!("init ./data dir :: ok");
assert!(!fs.exists("./weow.txt").await?);
eprintln!("upload ./weow.txt");
fs.upload(
"./weow.txt",
UploadRequest::default()
.with_content_type(Some("text/plain; charset=utf-8"))
.with_data("weow fluff"),
)
.await?;
eprintln!("upload ./weow.txt :: ok");
assert!(fs.exists("./weow.txt").await?);
assert_eq!(fs.blobs::<&str>(None, None).await?.len(), 1);
eprintln!("get blob ./weow.txt");
let Some(blob) = fs.blob("./weow.txt").await? else {
panic!("./weow.txt should exist");
};
eprintln!("get blob ./weow.txt :: ok");
assert!(matches!(blob, Blob::File(_)));
let Blob::File(blob) = blob else { unreachable!() };
eprintln!("read blob ./weow.txt data");
let content = String::from_utf8(blob.data.to_vec()).expect("valid utf-8"); eprintln!("read blob ./weow.txt data :: {content}");
assert_eq!(content.trim(), "weow fluff");
eprintln!("read blob ./weow.txt data :: ok");
eprintln!("delete blob ./weow.txt");
fs.delete("./weow.txt").await?;
assert!(!fs.exists("./weow.txt").await?);
eprintln!("delete blob ./weow.txt :: ok");
eprintln!("goodbye we're done :3");
Ok(())
}