Skip to content

Commit

Permalink
feat: Allow instantiating an UploadPart from its constituent parts (#552
Browse files Browse the repository at this point in the history
)

* feat: Allow instantiating an UploadPart from its constituent parts

* fix: Drop promises

* fix for reflect calls. tested and working.

* cargo fmt

---------

Co-authored-by: Kevin Flansburg <kevin.flansburg@gmail.com>
  • Loading branch information
lwansbrough and kflansburg authored Apr 28, 2024
1 parent f3eb1eb commit c6c83bb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions worker/src/r2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,20 @@ pub struct UploadedPart {
}

impl UploadedPart {
pub fn new(part_number: u16, etag: String) -> Self {
let obj = js_sys::Object::new();
Reflect::set(
&obj,
&JsValue::from_str("partNumber"),
&JsValue::from_f64(part_number as f64),
)
.unwrap();
Reflect::set(&obj, &JsValue::from_str("etag"), &JsValue::from_str(&etag)).unwrap();

let val: JsValue = obj.into();
Self { inner: val.into() }
}

pub fn part_number(&self) -> u16 {
self.inner.part_number().unwrap()
}
Expand Down

0 comments on commit c6c83bb

Please sign in to comment.