modifierApk.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { io } from "socket.io-client"
  2. import axios from "axios"
  3. import { setTimeout } from "timers/promises"
  4. import chalk from "chalk"
  5. const axiosInstance = axios.create({
  6. baseURL: "http://47.98.225.28/api",
  7. headers: {
  8. Authorization:
  9. "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InpvdW1hQWRtaW4iLCJzdWIiOjEsInJvbGVzIjpbImFkbWluIl0sImlhdCI6MTcyNjU4MTk1OH0.dQiHFYaDDa1qp4OpEHaH5SCZ9dafJ8uO9fAAc8HZgAo"
  10. }
  11. })
  12. const {
  13. data: { items: devices }
  14. } = await axiosInstance.post("/device", {
  15. page: { page: 1, limit: 1000 },
  16. search: {
  17. where: { online: true, busy: false },
  18. order: { name: "ASC" }
  19. }
  20. })
  21. const {
  22. data: { value: apkUrl }
  23. } = await axiosInstance.get("/sys-config/modifier_apk")
  24. console.log(chalk.green(`apkUrl: ${apkUrl}`))
  25. for (let device of devices) {
  26. if (parseInt(device.version) < 142) {
  27. console.log(chalk.green(`${device.name} update`))
  28. axiosInstance
  29. .post(
  30. `/device/${device.id}/sendMessage`,
  31. {
  32. action: "installApk",
  33. data: { apkUrl }
  34. },
  35. {
  36. timeout: 60000
  37. }
  38. )
  39. .catch(e => {
  40. console.log(chalk.red(e.message))
  41. })
  42. await setTimeout(500)
  43. }
  44. }