http now returns byte array and content type
Some checks failed
Build and Deploy / build-macos (push) Failing after 4s
Build and Deploy / build-windows (CLANG64) (push) Has been cancelled
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled
Build and Deploy / build-linux (push) Has been cancelled
Some checks failed
Build and Deploy / build-macos (push) Failing after 4s
Build and Deploy / build-windows (CLANG64) (push) Has been cancelled
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled
Build and Deploy / build-linux (push) Has been cancelled
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -169,6 +169,9 @@ static JSValue js_http_poll(JSContext *ctx, JSValueConst this_val,
|
||||
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);
|
||||
|
||||
@@ -68,6 +68,20 @@ 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()
|
||||
@@ -75,6 +89,7 @@ $_.receiver(e => {
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user