Created
September 20, 2020 10:14
-
-
Save sciabarracom/6dc03fa5e352575a054b3bb4805ce85b to your computer and use it in GitHub Desktop.
Importer using http
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function main(args) { | |
if(args.url) { | |
return new Promise(function(resolve) { | |
let url = new URL(args.url); | |
if(args.username) | |
url.username = args.username; | |
if(args.password) | |
url.password = args.password | |
require('http').get(url, function handleHttp(resp) { | |
let data = ''; | |
resp.on('data', (chunk) => { data += chunk; }); | |
resp.on('end', () => { resolve({"body": { "data": JSON.parse(data) }})}); | |
} | |
).on("error", (err) => {resolve({"error": err.message})}) | |
}) | |
} | |
return { "body": { "form": [ | |
{ | |
"type": "message", | |
"name": "note", | |
"description": "Importer using http only" | |
}, | |
{ | |
"name": "url", | |
"description": "URL", | |
"type": "string", | |
"required": false | |
}, | |
{ | |
"name": "username", | |
"description": "Username", | |
"type": "string", | |
"required": false | |
}, | |
{ | |
"name": "password", | |
"description": "Password", | |
"type": "password", | |
"required": true | |
}] | |
} } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment