mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
Merge pull request #108 from syumai/add-null-check-to-r2-conversion
add missing null checks to R2 conversion
This commit is contained in:
commit
18c1cd5093
@ -82,6 +82,9 @@ type R2HTTPMetadata struct {
|
||||
}
|
||||
|
||||
func toR2HTTPMetadata(v js.Value) (R2HTTPMetadata, error) {
|
||||
if v.IsUndefined() || v.IsNull() {
|
||||
return R2HTTPMetadata{}, nil
|
||||
}
|
||||
cacheExpiry, err := jsutil.MaybeDate(v.Get("cacheExpiry"))
|
||||
if err != nil {
|
||||
return R2HTTPMetadata{}, fmt.Errorf("error converting cacheExpiry: %w", err)
|
||||
|
@ -66,6 +66,9 @@ func AwaitPromise(promiseVal js.Value) (js.Value, error) {
|
||||
|
||||
// StrRecordToMap converts JavaScript side's Record<string, string> into map[string]string.
|
||||
func StrRecordToMap(v js.Value) map[string]string {
|
||||
if v.IsUndefined() || v.IsNull() {
|
||||
return map[string]string{}
|
||||
}
|
||||
entries := ObjectClass.Call("entries", v)
|
||||
entriesLen := entries.Get("length").Int()
|
||||
result := make(map[string]string, entriesLen)
|
||||
|
Loading…
x
Reference in New Issue
Block a user