UNPKG

weleakinfo-cli

Version:
74 lines (58 loc) 1.81 kB
"use strict"; require("dotenv").config(); const program = require('commander'); program.version('0.0.1'); const axios = require("axios"); const WELEAKINFO_PUBLIC_BASE = "https://api.weleakinfo.com/v3/public"; const WELEAKINFO_PRIVATE_BASE = "https://api.weleakinfo.com/v3"; const options = { keys: { public: process.env.WELEAKINFO_PUBLIC, private: process.env.WELEAKINFO_PRIVATE } }; program .option( "-t, --type <type>", "search type (username, email, password, hash, ip, name, phone, domain)" ) .option("-q, --query <query>", "query"); program.parse(process.argv); const headers = { // Must set User-Agent to name of application "User-Agent": "node-weleakinfo", // Authorization: Bearer $key Authorization: `Bearer ${options.keys.public}` // Accepts application/x-www-form-urlencoded }; async function search(type, query) { try { // If private API key exists, switch the url to private endpoint // private API is POST // public API is GET const url = (type, query) => { if (options.keys.private) { return `${WELEAKINFO_PRIVATE_BASE}/${type}/${query}`; } return `${WELEAKINFO_PUBLIC_BASE}/${type}/${query}?details=true`; }; let response = {}; if (options.keys.private) { headers.Authorization = `Bearer ${options.keys.private}`; headers["Content-Type"] = "application/x-www-form-urlencoded"; response = await axios.post(url(type, query), { headers }); } else { response = await axios.get(url(type, query), { headers }); } console.log(response.data); // TODO return here } catch (error) { console.error(error); } } console.log(program.type); console.log(program.query); (async () => { await search(program.type, program.query); })(); module.exports = {};