generated from bitprj/Intro-To-Serverless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.1.7.js
71 lines (61 loc) · 2.56 KB
/
test.1.7.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
let uri;
const fetch = require('node-fetch');
const args = require('minimist')(process.argv.slice(2))
const functions = require('./functions');
const user = args['user'];
const repo = args['repo'];
async function main() {
try {
uri = process.env.TWOCATZ_ENDPOINT
functions.checkSecret(uri, "TWOCATZ_ENDPOINT")
try {
const resp = await fetch(uri, {
method: 'GET'
});
var data = await resp.json()
let test = JSON.stringify(data)
functions.validateResponseStatus(resp, uri)
if (test.length < 3) {
console.error("No response... Try again!")
await functions.throwError("No response... Try again!", user, repo)
process.exit(1)
}
} catch (e) {
console.error("Did you return valid JSON? Try again!")
await functions.throwError("Did you return valid JSON? Try again!", user, repo)
process.exit(1)
}
try {
var catimage1 = data.cat1;
var catimage2 = data.cat2;
var newCat1 = Buffer.from(catimage1, 'base64').toString('ascii')
var newCat2 = Buffer.from(catimage2, 'base64').toString('ascii')
console.info("Yay! 🎉 We got your cat pictures 🐱")
} catch (e) {
console.error("Sorry! We couldn't find one or both of the cat pictures. Make sure you encoded in BASE64!")
await functions.throwError("Sorry! We couldn't find one or both of the cat pictures. Make sure you encoded in BASE64!", user, repo)
process.exit(1)
}
var array = ["Shreya", "Emily", "Fifi", "Beau", "Evelyn", "Julia", "Daniel", "Fardeen"]
var names = data.names
var name1 = names[0]
var name2 = names[1]
try {
if (array.includes(name1) && array.includes(name2)) {
console.info(`Yay! 🎉 Thanks for getting our names right. We got: "${name1}" and "${name2}"`)
} else {
console.error(`Sorry, your names, "${name1}" and "${name2}", were not correct.`)
await functions.throwError(`Sorry, your names, '${name1}' and '${name2}', were not correct.`, user, repo)
process.exit(1)
}
} catch (e) {
console.error(`Sorry, your names, '${name1}' and '${name2}', were not correct.`)
await functions.throwError(e, user, repo)
process.exit(1)
}
}
catch (e) {
await functions.throwError(e, user, repo)
}
}
main();