common.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. const chalk = require('chalk');
  2. const clear = require('clear');
  3. const figlet = require('figlet');
  4. const fs = require('fs')
  5. var pjson = require('../package.json');
  6. const fetch = require('node-fetch');
  7. module.exports = {
  8. header: (page) => {
  9. clear();
  10. console.log(
  11. chalk.red(
  12. figlet.textSync('MiWatch Kleaner', {
  13. horizontalLayout: 'full'
  14. })
  15. )
  16. );
  17. console.log(chalk.red(' ' + pjson.version));
  18. console.log();
  19. console.log(
  20. chalk.red(
  21. '-------------------------------------------------------------------------------------------------------'
  22. )
  23. )
  24. console.log(chalk.blue(page))
  25. module.exports.ipCheck()
  26. console.log(chalk.red('----------'))
  27. },
  28. pause: async (time) => {
  29. await new Promise(resolve => setTimeout(resolve, time));
  30. },
  31. ipCheck: async () => {
  32. const miwatchData = JSON.parse(fs.readFileSync('./data/MiWatch.json', 'utf8'));
  33. if (miwatchData.ipAddress === "") {
  34. console.log(chalk.white('MiWatch IP: ') + chalk.red('Not Connected'))
  35. } else {
  36. console.log(chalk.white('MiWatch IP: ' + chalk.green(miwatchData.ipAddress)))
  37. }
  38. },
  39. downloadFile: async (url, path) => {
  40. const res = await fetch(url);
  41. await new Promise((resolve, reject) => {
  42. const fileStream = fs.createWriteStream(path);
  43. res.body.pipe(fileStream);
  44. res.body.on("error", (err) => {
  45. reject(err);
  46. });
  47. fileStream.on("finish", function() {
  48. resolve();
  49. });
  50. });
  51. },
  52. getCompatibleAppsList: async () => {
  53. let settings = { method: "Get" };
  54. const response = await fetch("http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/compatibleApps.json", settings)
  55. .then(res => res.json())
  56. return response
  57. },
  58. }