diff options
author | bptato <nincsnevem662@gmail.com> | 2023-09-09 12:45:58 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-09-09 12:45:58 +0200 |
commit | a4ae0ae16f8f3fbe706e9a4ac23557a4fe790c4b (patch) | |
tree | 75e226af1783d021b05aa1d935c551b92bdf15c5 /src/types | |
parent | 530fc9f9212802db84c8ef0a9854e88b0d389944 (diff) | |
download | chawan-a4ae0ae16f8f3fbe706e9a4ac23557a4fe790c4b.tar.gz |
blob: use JSDict
Diffstat (limited to 'src/types')
-rw-r--r-- | src/types/blob.nim | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/types/blob.nim b/src/types/blob.nim index 0c4b30b9..54071c33 100644 --- a/src/types/blob.nim +++ b/src/types/blob.nim @@ -1,5 +1,6 @@ import options +import js/dict import js/fromjs import js/javascript import utils/mimeguess @@ -54,8 +55,16 @@ proc newWebFile*(path: string, webkitRelativePath = ""): WebFile = webkitRelativePath: webkitRelativePath ) +type + BlobPropertyBag = object of JSDict + `type`: string + #TODO endings + + FilePropertyBag = object of BlobPropertyBag + #TODO lastModified: int64 + proc newWebFile(ctx: JSContext, fileBits: seq[string], fileName: string, - options = none(JSValue)): WebFile {.jsctor.} = + options = FilePropertyBag()): WebFile {.jsctor.} = let file = WebFile( isfile: false, path: fileName, @@ -72,16 +81,11 @@ proc newWebFile(ctx: JSContext, fileBits: seq[string], fileName: string, copyMem(addr buf[i], unsafeAddr blobPart[0], blobPart.len) i += blobPart.len file.size = uint64(len) - if options.isSome: - block ctype: - let t = fromJS[string](ctx, JS_GetPropertyStr(ctx, options.get, "type")) - if t.isNone: + block ctype: + for c in options.`type`: + if c notin char(0x20)..char(0x7E): break ctype - for c in t.get: - if c notin char(0x20)..char(0x7E): - break ctype - file.ctype &= c.tolower() - #TODO lastmodified + file.ctype &= c.tolower() return file #TODO File, Blob constructors |