Pretty straightforward issue - I'm using fetch
in an autotask to fetch metadata for an ERC721.
Some folks are starting to return data-uri stringss of base-64 encoded json at tokenURI, such as
"data:application/json;base64,eyJhdHRyaWJ1dGVzIjp7ImFnZ3Jlc3Npb24iOjAsImF3YXJlbmVzcyI6MCwiZGV0ZXJtaW5hdGlvbiI6MCwicG93ZXIiOjAsInJlc2lsaWVuY2UiOjAsInNwZWVkIjowfX0="
In most browsers and node, this is a fine things to fetch
and conveniently works the same as an https url.
In an autotask, I get the following error: Only HTTP(S) protocols are supported
AUTOTASK START
2021-10-11T00:45:03.433Z ERROR Invoke Error {"errorType":"TypeError","errorMessage":"Only HTTP(S) protocols are supported","stack":["TypeError: Only HTTP(S) protocols are supported"," at getNodeRequestOptions (/opt/nodejs/node_modules/node-fetch/lib/index.js:1303:9)"," at /opt/nodejs/node_modules/node-fetch/lib/index.js:1404:19"," at new Promise (<anonymous>)"," at fetch (/opt/nodejs/node_modules/node-fetch/lib/index.js:1401:9)"," at /var/task/index.js:94:42"," at step (/var/task/index.js:66:23)"," at Object.next (/var/task/index.js:47:53)"," at fulfilled (/var/task/index.js:37:58)"," at processTicksAndRejections (internal/process/task_queues.js:97:5)"]}
END RequestId: b36078b1-cd07-48cd-ba1c-9c4c5dcc8340
AUTOTASK COMPLETE
I'm able to work around it like this:
const json = Buffer.from(tokenURI.substring(29), 'base64').toString();
const result = JSON.parse(json);
But it would be nice not to have to worry about the conditional.
Any chance data-uris could be fetched in an autotask? Or am I being really naive about the security implications?