deviceId.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { io } from "socket.io-client"
  2. import axios from "axios"
  3. import { setTimeout } from "timers/promises"
  4. const axiosInstance = axios.create({
  5. baseURL: "http://47.98.225.28/api",
  6. headers: {
  7. Authorization:
  8. "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InpvdW1hQWRtaW4iLCJzdWIiOjEsInJvbGVzIjpbImFkbWluIl0sImlhdCI6MTcyNjU4MTk1OH0.dQiHFYaDDa1qp4OpEHaH5SCZ9dafJ8uO9fAAc8HZgAo"
  9. }
  10. })
  11. const {
  12. data: { items: devices }
  13. } = await axiosInstance.post("/device", {
  14. page: { page: 1, limit: 1000 },
  15. search: { where: { online: true }, order: { name: "ASC" } }
  16. })
  17. for (let device of devices) {
  18. if (device.id.length === 16) {
  19. console.log(device.name)
  20. try {
  21. const {
  22. data: { out }
  23. } = await axiosInstance.post(
  24. `/device/${device.id}/sendMessage`,
  25. {
  26. action: "runScript",
  27. data: {
  28. script: "getprop ro.serialno"
  29. }
  30. },
  31. {
  32. timeout: 2000
  33. }
  34. )
  35. const serial = out.trim()
  36. if (serial && serial != device.id) {
  37. axiosInstance.post(`/device/${device.id}/sendMessage`, {
  38. action: "updateDevice",
  39. data: {
  40. id: serial
  41. }
  42. })
  43. }
  44. } catch (e) {
  45. console.log(e.message)
  46. }
  47. }
  48. }