pengunjung.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import axios from "@/config/axios";
  2. import axios2 from "axios";
  3. export const createPengunjung = async () => {
  4. try {
  5. const jsonip = await axios2.get("https://ip-api.io/json");
  6. const res = await axios.post("/pengunjung/create", {
  7. os: navigator.userAgentData.platform,
  8. ipv4: jsonip.data.ip,
  9. location: {
  10. country: jsonip.data.country_name,
  11. region: jsonip.data.region_name,
  12. city: jsonip.data.city,
  13. lat: jsonip.data.latitude,
  14. lon: jsonip.data.longitude,
  15. timezone: jsonip.data.time_zone,
  16. },
  17. });
  18. return res.data;
  19. } catch (error) {
  20. console.log("error", error);
  21. return false;
  22. }
  23. };
  24. export const getPengunjung = async (token) => {
  25. try {
  26. const res = await axios.get(`/pengunjung`, { headers: { Authorization: token } });
  27. return res.data;
  28. } catch (error) {
  29. console.log("error", error);
  30. return false;
  31. }
  32. };
  33. export const getPengunjungPublic = async ({ bulan, tahun }) => {
  34. try {
  35. let url = "/public/pengunjung";
  36. if (bulan || tahun) {
  37. url += "?";
  38. if (bulan) {
  39. url += `bulan=${bulan}`;
  40. }
  41. if (tahun) {
  42. url += `bulan=${tahun}`;
  43. }
  44. }
  45. const res = await axios.get(url);
  46. return res.data;
  47. } catch (error) {
  48. console.log("error", error);
  49. return false;
  50. }
  51. };