Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Leon committed Mar 3, 2024
1 parent fe667f2 commit ef0f7d3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ args = ["build", "--target", ""]
[tasks.build-web]
dependencies = ["git-submodules-update"]
command = "cargo"
args = ["build","--target", "wasm32-unknown-unknown"]
args = ["build","--target", "wasm32-unknown-unknown"]
2 changes: 1 addition & 1 deletion bucket-api
Submodule bucket-api updated 1 files
+1 −1 proto/bucket.proto
4 changes: 2 additions & 2 deletions src/controller/bucket/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ pub async fn download_files_from_bucket<DH: BucketFileDownloadHandler, T>(
path: file.file_path,
date: None,
size_in_bytes: file.file_size_in_bytes,
file_format: mime::Mime::from_str(file.file_format.as_str())?,
//file_format: mime::Mime::from_str(file.file_format.as_str())?,
};

let mut download_handler = create_file_download_handler_hook.handle(
Expand Down Expand Up @@ -277,7 +277,7 @@ pub async fn bucket_download<DH: BucketFileDownloadHandler, T>(
path: file.file_path.clone(),
date: None,
size_in_bytes: file.file_size_in_bytes,
file_format: mime::Mime::from_str(file.file_format.as_str())?,
//file_format: mime::Mime::from_str(file.file_format.as_str())?,
};
let mut download_handler = create_download_handler.handle(
virtual_file,
Expand Down
2 changes: 1 addition & 1 deletion src/controller/bucket/io/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct VirtualFileDetails {
pub path: String,
pub date: Option<time::OffsetDateTime>,
pub size_in_bytes: u64,
pub file_format: mime::Mime,
//pub file_format: mime::Mime,
}

/// Traits to collectively implement the read/write to the local filesystem depending on target.
Expand Down
26 changes: 9 additions & 17 deletions src/controller/bucket/io/web_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ pub enum WebBucketFileError {
TryFromIntError(#[from] TryFromIntError),
#[error(transparent)]
FromStrError(#[from] FromStrError),

}


#[derive(thiserror::Error, Debug)]
pub enum ConvertHtmlInputElementToFileListError {
// Is this even possible?
Expand Down Expand Up @@ -66,10 +68,7 @@ impl BucketFileTrait for VirtualWebBucketFile {
type Error = WebBucketFileError;

type FileHandle = WebFileHandle;
fn new(filename: &str, mime: &Mime) -> Result<Self, Self::Error>
where
Self: Sized,
{
fn new(filename: &str, mime:&Mime) -> Result<Self, Self::Error> where Self: Sized {
let file_handle = gloo::file::File::new_with_options(
&filename,
"",
Expand All @@ -79,6 +78,7 @@ impl BucketFileTrait for VirtualWebBucketFile {
Ok(Self {
file_handle,
filename: filename.to_string(),
file_type: mime,
})
}
fn from(file_handle: Self::FileHandle, filename: String, mime: &Mime) -> Self {
Expand Down Expand Up @@ -111,8 +111,7 @@ impl BucketFileTrait for VirtualWebBucketFile {
}

fn get_extension(&self) -> Result<String, Self::Error> {
let extension = self
.filename
let extension = self.filename
.rsplit_once('.')
.ok_or(WebBucketFileError::NoExtension)?;
let (_, extension) = extension; // Unwrap the result
Expand All @@ -135,8 +134,7 @@ impl BucketFileTrait for VirtualWebBucketFile {

fn write_chunk(&self, chunk: &vec::Vec<u8>, offset: u64) -> Result<(), Self::Error> {
let web_file: &web_sys::File = self.file_handle.as_ref();
let mut writable_stream =
WritableStream::from_raw(web_file.stream().unchecked_into()).into_stream();
let mut writable_stream = WritableStream::from_raw(web_file.stream().unchecked_into()).into_stream();
let mut writer = writable_stream.get_writer();

let array = Uint8Array::new_with_length(chunk.len() as u32);
Expand All @@ -149,8 +147,7 @@ impl BucketFileTrait for VirtualWebBucketFile {

fn write_stream(&self, stream: &dyn Write) -> Result<(), Self::Error> {
let web_file: &web_sys::File = self.file_handle.as_ref();
let mut writable_stream =
WritableStream::from_raw(web_file.stream().unchecked_into()).into_stream();
let mut writable_stream = WritableStream::from_raw(web_file.stream().unchecked_into()).into_stream();
let mut writer = writable_stream.get_writer();

todo!()
Expand Down Expand Up @@ -179,19 +176,14 @@ mod tests {

// Would have to use trunk test which is still under development https://github.com/trunk-rs/trunk/issues/20
fn test_write_to_web_file() {
// https://stackoverflow.com/questions/76855488/no-click-method-defined-on-element-when-created-via-web-sys
// https://stackoverflow.com/questions/76855488/no-click-method-defined-on-element-when-created-via-web-sys
let document: Document = web_sys::window().unwrap().document().unwrap();
document.create_element("input");
let input: Element = document.create_element("input").unwrap();
input.set_attribute("type", "file").unwrap();
// For debugging purposes, save a reference to a global variable so I can inspect it from the JavaScript console
let input_jsval: JsValue = input.clone().into();
js_sys::Reflect::set(
&js_sys::global(),
&JsValue::from_str("debug_input"),
&input_jsval,
)
.unwrap();
js_sys::Reflect::set(&js_sys::global(), &JsValue::from_str("debug_input"), &input_jsval).unwrap();

// Attempt to click it
let input_html_element: HtmlElement = input_jsval.clone().into();
Expand Down

0 comments on commit ef0f7d3

Please sign in to comment.