use crate::StorageService;
use bytes::Bytes;
use openvet_common::{rust::*, storage::*, tree::Node};
use semver::Version;
use std::{
collections::{BTreeMap, BTreeSet},
sync::Arc,
};
use tarpc::context::Context;
use tokio::sync::Mutex;
use tracing::*;
#[derive(Clone, Debug)]
pub struct StorageHandler {
service: StorageService,
}
impl StorageHandler {
pub fn new(service: StorageService) -> Self {
Self { service }
}
}
impl Storage for StorageHandler {
async fn ping(self, _: Context, message: String) -> String {
message
}
async fn version(self, _: Context) -> Version {
env!("CARGO_PKG_VERSION").parse().unwrap()
}
async fn crate_list(self, _: Context) -> BTreeSet<CrateName> {
Default::default()
}
async fn crate_info(self, _: Context, krate: CrateName) -> Option<CrateInfo> {
Default::default()
}
#[instrument(skip(self, info))]
async fn crate_write(self, _: Context, info: CrateInfo) {
let result = self.service.crate_sync(info).await;
if let Err(error) = result {
error!("{error}");
}
}
async fn object_get(self, _: Context, hash: Checksum) -> Option<Bytes> {
Default::default()
}
async fn object_exists(self, _: Context, hash: Checksum) -> bool {
false
}
async fn object_write(self, _: Context, bytes: Bytes) -> Checksum {
todo!()
}
async fn object_gc(self, _: Context) {}
async fn sources_missing(self, _: Context, limit: usize) -> BTreeSet<CrateVersion> {
Default::default()
}
async fn crate_tree_write(self, _: Context, krate: CrateVersion, root: Node) {}
}