diff --git a/source/jsffi.c b/source/jsffi.c index 47cf1f04..170964a1 100644 --- a/source/jsffi.c +++ b/source/jsffi.c @@ -7665,7 +7665,6 @@ void ffi_load(JSContext *js) QJSCLASSPREP_FUNCS(SDL_GPURenderPass) QJSCLASSPREP_FUNCS(SDL_GPUComputePass) - QJSCLASSPREP_NO_FUNCS(SDL_GPUCopyPass) QJSCLASSPREP_NO_FUNCS(SDL_GPUFence) QJSCLASSPREP_NO_FUNCS(SDL_GPUTransferBuffer) diff --git a/source/qjs_http.c b/source/qjs_http.c index 08121220..18854127 100644 --- a/source/qjs_http.c +++ b/source/qjs_http.c @@ -168,6 +168,9 @@ static JSValue js_http_poll(JSContext *ctx, JSValueConst this_val, CURL *easy = msg->easy_handle; HttpRequest *req = NULL; curl_easy_getinfo(easy, CURLINFO_PRIVATE, (char **)&req); + + char *ct = NULL; + curl_easy_getinfo(easy, CURLINFO_CONTENT_TYPE, &ct); // Remove from multi-handle curl_multi_remove_handle(g_curl_multi, easy); @@ -180,10 +183,11 @@ static JSValue js_http_poll(JSContext *ctx, JSValueConst this_val, if (JS_IsFunction(req->ctx, req->callback)) { JSValue arg = JS_NewObject(req->ctx); if (req->curl_result == CURLE_OK) { - JSValue data = (req->response && req->size > 0) ? - JS_NewStringLen(req->ctx, req->response, req->size) : JS_NULL; - JS_DefinePropertyValueStr(req->ctx, arg, "data", data, JS_PROP_C_W_E); - JS_DefinePropertyValueStr(req->ctx, arg, "error", JS_NULL, JS_PROP_C_W_E); + JS_SetPropertyStr(req->ctx, arg, "data", + JS_NewArrayBufferCopy(req->ctx, req->response, req->size)); + JS_SetPropertyStr(req->ctx, arg, "error", JS_UNDEFINED); + + if (ct) JS_SetPropertyStr(req->ctx, arg, "type", JS_NewString(req->ctx, ct)); } else { JS_DefinePropertyValueStr(req->ctx, arg, "data", JS_NULL, JS_PROP_C_W_E); const char *err_str = curl_easy_strerror(req->curl_result); diff --git a/tests/qr_drag.js b/tests/qr_drag.js index 3d275736..bbaff906 100644 --- a/tests/qr_drag.js +++ b/tests/qr_drag.js @@ -68,13 +68,28 @@ function strToArrayBuffer(binStr) { return view.buffer; } +var http = use('http') + +function is_url(str) +{ + return /^https?:\/\/[^\s/$.?#].[^\s]*$/i.test(str) +} + +function parse_data(res) +{ + var data = res.data + console.log("DOWNLOAD DONE! size was " + data.byteLength) + console.log(res.type) +} + $_.receiver(e => { if (e.type === 'quit') os.exit() - + switch(e.type) { case "drop_file": console.log(`got ${e.data} dropped`) + break img = e.data var image = graphics.texture(e.data) var data = qr.decode(image.surface.pixels(), image.surface.width(), image.surface.height(), image.surface.pitch()) @@ -83,11 +98,21 @@ $_.receiver(e => { console.log(data.byteLength) var ddata = miniz.decompress(data, true) console.log(ddata) + case "drop_text": + console.log(`text ${e.data} dropped`) + // if e.data is a url, fetch it + if (is_url(e.data)) { + console.log('fetching!') + http.fetch(e.data, parse_data) + } + + break } }) function loop() { + http.poll(); var now = os.now() render.clear([22/255,120/255,194/255,255/255]) render.camera(camera)