pinnacleClient.js 1.8 KB

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