pinnacleClient.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import axios from "axios";
  2. import { HttpsProxyAgent } from "https-proxy-agent";
  3. import { Logs } from "./logs.js";
  4. const BaseURL = {
  5. pinnacle: "https://api.pinnacle888.com",
  6. pstery: "http://127.0.0.1:9055",
  7. }
  8. export const pinnacleRequest = async (options) => {
  9. const {
  10. endpoint,
  11. params = {},
  12. username,
  13. password,
  14. method = "GET",
  15. data,
  16. proxy,
  17. timeout = 10000,
  18. } = options;
  19. if (!endpoint || !username || !password) {
  20. throw new Error("endpoint、username、password is required");
  21. }
  22. const authHeader = `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`;
  23. const axiosConfig = {
  24. baseURL: BaseURL.pinnacle,
  25. url: endpoint,
  26. method,
  27. headers: {
  28. "Authorization": authHeader,
  29. "Accept": "application/json",
  30. "Content-Type": "application/json",
  31. },
  32. params,
  33. data,
  34. timeout,
  35. };
  36. if (proxy) {
  37. axiosConfig.proxy = false;
  38. axiosConfig.httpsAgent = new HttpsProxyAgent(proxy);
  39. }
  40. return axios(axiosConfig).then(res => res.data);
  41. }
  42. export const getPsteryRelations = async (mk=-1) => {
  43. const axiosConfig = {
  44. baseURL: BaseURL.pstery,
  45. url: '/api/pstery/get_games_relation',
  46. method: 'GET',
  47. params: {
  48. mk,
  49. },
  50. proxy: false,
  51. };
  52. return axios(axiosConfig).then(res => res.data);
  53. }
  54. export const updateBaseEvents = async (data) => {
  55. const axiosConfig = {
  56. baseURL: BaseURL.pstery,
  57. url: '/api/pstery/update_base_events',
  58. method: 'POST',
  59. headers: {
  60. 'Content-Type': 'application/json',
  61. },
  62. data: JSON.stringify(data),
  63. proxy: false,
  64. };
  65. axios(axiosConfig).then(res => res.data)
  66. .then(() => {
  67. Logs.outDev('update base events success', data);
  68. })
  69. .catch(err => {
  70. Logs.err('failed to update base events:', err.message);
  71. });
  72. }
  73. export const notifyException = async (message) => {
  74. const axiosConfig = {
  75. baseURL: BaseURL.pstery,
  76. url: '/api/pstery/notify_exception',
  77. method: 'POST',
  78. data: { message },
  79. proxy: false,
  80. };
  81. axios(axiosConfig).then(res => res.data)
  82. .then(() => {
  83. Logs.out('notify exception success');
  84. })
  85. .catch(err => {
  86. Logs.err('failed to notify exception:', err.message);
  87. });
  88. }