-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
64 lines (49 loc) · 1.92 KB
/
cli.js
File metadata and controls
64 lines (49 loc) · 1.92 KB
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
#!/usr/bin/env node
import fetch from 'node-fetch'
import readline from 'readline/promises'
const isValidUrl = urlString=> {
var urlPattern = new RegExp('^(https?:\\/\\/)?'+ // validate protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // validate domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // validate OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // validate port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // validate query string
'(\\#[-a-z\\d_]*)?$','i'); // validate fragment locator
return !!urlPattern.test(urlString);
}
const rl = readline.createInterface({input: process.stdin, output: process.stdout})
const ppl = await rl.question("how many people are in your team? ")
const numPpl = Number(ppl)
let team = []
for (let i = 0; i < numPpl; i++) {
let email = await rl.question(`what is person ${i + 1}'s email? `)
const req = await fetch(`https://shipper-js.vercel.app/api/check`, {body: email, method: "POST"})
const res = await req.text()
let valid_email = (res == "true")
while (!valid_email) {
email = await rl.question("invalid email, try again: ")
const req = await fetch(`https://shipper-js.vercel.app/api/check`, {body: email, method: "POST"})
const res = await req.text()
valid_email = (res == "true")
}
team.push(email)
}
let link = await rl.question("link your repository: ")
let valid_url = isValidUrl(link)
while (!valid_url) {
link = await rl.question("invalid url, try again: ")
valid_url = isValidUrl(link)
}
const title = await rl.question("finally, add a title to your submission: ")
const bo = JSON.stringify({team: team, link: link, title: title})
const submitReq = await fetch(`https://shipper-js.vercel.app/api/ship`,
{
method: "POST",
body: bo
})
const submitRes = await submitReq.text()
if (submitRes == "ok") {
console.log('it submitted')
} else {
console.log("it didn't work, talk to suhas ig")
}
rl.close()