From 775d867addaa70f02ce60b3f58484da10e8a1dc5 Mon Sep 17 00:00:00 2001 From: Michael Chung Date: Tue, 19 Dec 2023 03:05:39 -0500 Subject: [PATCH] Ok fixed compilation issues. --- .../src/public/files/file_descriptor.rs | 42 +++++++++---------- .../public/files/remote_cloud_file_manager.rs | 21 +++++----- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/crates/_types/buckets/src/public/files/file_descriptor.rs b/crates/_types/buckets/src/public/files/file_descriptor.rs index 811bbee559..9ff72f9773 100644 --- a/crates/_types/buckets/src/public/files/file_descriptor.rs +++ b/crates/_types/buckets/src/public/files/file_descriptor.rs @@ -17,14 +17,14 @@ pub trait FileDescriptor { } // this will be the type of file // e.g requires! a period .safetensors .bin .jpg - fn get_suffix(&self)->&str { - return "implement".to_string().as_ref(); + fn get_suffix(&self)->String { + return "implement".to_string(); } // This will be the prefix of the media type or the weights type. // name of the weights or the name of the media type // vall-e_prompt, loRA, sd15, sdxl when implmenting add to the end - fn get_prefix(&self)->&str { - return "implement".to_string().as_ref(); + fn get_prefix(&self)->String { + return "implement".to_string(); } // This will be ensure that the right bucket is picked @@ -33,21 +33,21 @@ pub trait FileDescriptor { } } -pub struct FileBucketDirectory<'a> { - file_object_hash: &'a str, - cloud_directory_hash: &'a str, - remote_cloud_base_directory: &'a str, - full_remote_cloud_file_path: &'a str, - file_name: &'a str, +pub struct FileBucketDirectory { + file_object_hash: String, + cloud_directory_hash: String, + remote_cloud_base_directory: String, + full_remote_cloud_file_path: String, + file_name: String, file_descriptor: Box } -impl FileBucketDirectory<'_> { - pub fn generate_new(file_descriptor: impl FileDescriptor) -> Self { +impl FileBucketDirectory { + pub fn generate_new(file_descriptor: Box) -> Self { Self::from_object_hash(file_descriptor) } - fn from_object_hash(file_descriptor: impl FileDescriptor) -> Self { + fn from_object_hash(file_descriptor: Box) -> Self { let cloud_path_entropy = crockford_entropy_lower(32); let file_name_entropy = crockford_entropy_lower(32); @@ -55,21 +55,21 @@ impl FileBucketDirectory<'_> { let middle = hashed_directory_path_long_string::hashed_directory_path_long_string(cloud_path_entropy.as_ref()); // gets you cloud bucket path e.g weights/a/b/c/d/clould_path_entropy - let remote_cloud_base_directory = format!("{}/{}{}", file_descriptor.remote_directory_path().as_ref(), middle, cloud_path_entropy.as_ref()); + let remote_cloud_base_directory = format!("{}/{}{}", file_descriptor.remote_directory_path(), middle, cloud_path_entropy); // gets you name of the file with suffix and prefix and entropy in the centre - let file_name = format!("{}_{}.{}", file_descriptor.get_prefix(), file_name_entropy.as_ref(), file_descriptor.get_suffix()); + let file_name = format!("{}_{}.{}", file_descriptor.get_prefix(), file_name_entropy, file_descriptor.get_suffix()); // note: no longer optional because it's easy to know what it would be in the db explicit is better than implcit. // This is the full path you upload to. let full_remote_cloud_file_path = format!("{}/{}", remote_cloud_base_directory , file_name); Self { - file_object_hash: file_name_entropy.as_ref(), - cloud_directory_hash: cloud_path_entropy.as_ref(), - remote_cloud_base_directory: remote_cloud_base_directory.as_ref(), - full_remote_cloud_file_path: full_remote_cloud_file_path.as_ref(), - file_name:file_name.as_ref(), - file_descriptor:Box::new(file_descriptor) + file_object_hash: file_name_entropy, + cloud_directory_hash: cloud_path_entropy, + remote_cloud_base_directory: remote_cloud_base_directory, + full_remote_cloud_file_path: full_remote_cloud_file_path, + file_name:file_name, + file_descriptor:file_descriptor } } diff --git a/crates/_types/buckets/src/public/files/remote_cloud_file_manager.rs b/crates/_types/buckets/src/public/files/remote_cloud_file_manager.rs index 80c32e76f7..d1424d6a62 100644 --- a/crates/_types/buckets/src/public/files/remote_cloud_file_manager.rs +++ b/crates/_types/buckets/src/public/files/remote_cloud_file_manager.rs @@ -21,7 +21,7 @@ struct WebFileManager { impl WebFileManager { // bucket_client:BucketClients - fn new(file_descriptor: dyn FileDescriptor) -> WebFileManager { + fn new(file_descriptor: Box) -> WebFileManager { WebFileManager { // bucket_client: bucket_client, file_descriptor: file_descriptor @@ -30,18 +30,19 @@ impl WebFileManager { // also include bucket details here - pub fn download_file(&self, system_file_path:String) -> Result<(),AnyhowError> { + // pub fn download_file(&self, system_file_path:String) -> Result<(),AnyhowError> { - } + // } // return error or success with meta data. pub fn upload_file(&self, system_file_path:String) -> Result { - let file_descriptor = self.file_descriptor.clone(); + // let bucket_client = self.bucket_client.clone(); - if file_descriptor.is_public() { + if self.file_descriptor.is_public() { } - Ok(Self::get_file_meta_data(system_file_path.clone())) + let result = Self::get_file_meta_data(system_file_path.clone())?; + Ok(result) } // Retrieve the metadata from the file @@ -49,14 +50,15 @@ impl WebFileManager { let file_size_bytes = file_size(system_file_path.clone())?; let sha256_checksum = sha256_hash_file(system_file_path.clone())?; + let bytes = file_read_bytes(system_file_path)?; let mimetype = get_mimetype_for_bytes(&bytes).unwrap_or("application/octet-stream"); - FileMetaData { + Ok(FileMetaData { file_size_bytes: file_size_bytes, sha256_checksum: sha256_checksum, mimetype: mimetype.to_string() - }; + }) } } @@ -66,9 +68,6 @@ impl WebFileManager { // should be able to take prefix suffix and entrpy to generate a file descriptor -// should return this once properly uploaded. -// let file_size_bytes = file_size(weight_file_path.clone())?; -// let sha256_checksum = sha256_hash_file(weight_file_path.clone())?; #[cfg(test)] mod tests {