This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
63 lines (62 loc) · 2.25 KB
/
cli.js
File metadata and controls
63 lines (62 loc) · 2.25 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
require("dotenv").config()
const Admin = require("./ZeroNet/AdminZite"),
SiteMeta = require("./ZeroNet/SiteMeta"),
DomainResolver = require("./ZeroNet/DomainResolver"),
DataBase = require("./DataBase")
let admin = null
require('yargs')
.command('getInfo <siteAddr>', 'Get siteInfo for given site address', () => { }, async (argv) => {
console.log(await SiteMeta.getWsSiteInfo(argv.siteAddr))
})
.command('getSite <siteAddr>', 'Get siteObj for given site address', () => { }, async (argv) => {
DataBase.on("connected", async () => {
console.log("Getting data for " + argv.siteAddr)
console.log(await DataBase.getSite(argv.siteAddr))
process.exit()
})
DataBase.connect()
})
.command('stats', "Get stats", () => { }, async () => {
console.log(`Total sites in site.json: ${Object.keys(await SiteMeta.reloadSitesJson()).length}`)
let incomplete = 0, done = 0
for (let addr in global.sitesJson) {
try {
if (Object.keys(global.sitesJson[addr].cache.bad_files).length > 0) {
incomplete++
} else
done++
} catch {
incomplete++
}
}
console.log(`-- Incomplete:${incomplete}, Done:${done}`)
})
.command("admin <command> [args...]", "Send command to zeronet, e.g. siteList", () => { }, async (argv) => {
async function sendCmd() {
try {
console.log(await admin.cmdp(argv.command, argv.args))
} catch (e) {
console.log("Error: " + e)
}
process.exit()
}
if (!admin) {
admin = new Admin()
admin.on("wsOpen", sendCmd)
} else
await sendCmd()
})
.command("resolve <domain>", "Resolve a domain", () => { }, (argv) => {
console.log(DomainResolver.resolveDomain(argv.domain))
})
.command("resetDatabase", "Clear the database", () => { }, async () => {
DataBase.on("connected", async () => {
console.log("OK")
process.exit()
})
DataBase.connect(true)
})
.demandCommand(1, "")
.help("h")
.alias("h", "help")
.argv