{"size": 992, "ext": "js", "max_stars_repo_path": "commands/piHole/disable.js", "max_stars_repo_name": "ThisIsBenny/raycast-script-commands", "max_stars_repo_stars_event_min_datetime": "2022-03-25T13:24:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T13:24:27.000Z", "max_issues_repo_path": "commands/piHole/disable.js", "max_issues_repo_name": "ThisIsBenny/raycast-script-commands", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "commands/piHole/disable.js", "max_forks_repo_name": "ThisIsBenny/raycast-script-commands", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 34.2068965517, "max_line_length": 86, "alphanum_fraction": 0.6754032258}
#!/usr/bin/env node

// @raycast.schemaVersion 1
// @raycast.title Disable PiHole
// @raycast.mode silent
// @raycast.icon images/piHoleLogo.png
// @raycast.description Disable PiHole for X min
// @raycast.author Benny Hierl
// @raycast.authorURL https://github.com/ThisIsBenny/raycast-script-commands
// @raycast.argument1 { "type": "text", "placeholder": "Minutes", "optional": true}

const config = require('./config');
const { sendRequest, defaultError, capitalizeFirstLetter } = require('./helper');

const [minutes] = process.argv.slice(2)
let url = `/admin/api.php?disable&auth=${config.token}`;

if (minutes !== '') {
  const seconds = parseInt(minutes) * 60;
  url = `/admin/api.php?disable=${seconds}&auth=${config.token}`;
}

sendRequest(url).then((data) => {
  let postfix = ''
  if (minutes !== '') {
    postfix = ` for ${minutes} ` + ((parseInt(minutes) === 1) ? 'minute' : 'minutes');
  }
  console.log(`${capitalizeFirstLetter(data.status)}${postfix}`)
}).catch(defaultError)