{"ast":null,"code":"import axios from 'axios';\nimport jwt from 'jwt-decode';\nimport { toast } from 'react-toastify';\n\nfunction getHeaders() {\n const user = JSON.parse(localStorage.getItem('user'));\n\n if (user && user.jwt) {\n var unixtime = Math.round(new Date().getTime() / 1000);\n\n if (user.exp < unixtime) {\n // Trigger refresh\n localStorage.removeItem('user');\n window.location.reload(); // toast.warning(\"Session expired. Please log in again\")\n // window.location.reload();\n\n return {};\n }\n\n return {\n Authorization: 'Bearer ' + user.jwt\n };\n } else {\n return {};\n }\n}\n\nfunction getUserUuid() {\n // TODO: move this to use Context values instead.\n const user = JSON.parse(localStorage.getItem('user'));\n\n if (user && user.uuid) {\n return user.uuid;\n } else {\n return '';\n }\n}\n\nfunction handleErrorResp(error) {\n if (error.response) {\n if (error.response.status === 401) {\n toast.error('Unauthorized');\n } else if (error.response.status === 429) {\n toast.error('Rate limited. Please try again shortly');\n } else {\n toast.error('An unknown error has occurred');\n }\n } else {\n toast.error('Failed to connect to API');\n }\n\n return {};\n}\n\nexport const PostLogin = formValues => {\n return axios.post(process.env.REACT_APP_API_URL + \"/api/v1/login\", formValues).then(response => {\n if (response.data.token) {\n let expandedUser = jwt(response.data.token);\n let user = {\n jwt: response.data.token,\n uuid: expandedUser.sub,\n exp: expandedUser.exp,\n username: expandedUser.username,\n admin: expandedUser.admin,\n mod: expandedUser.mod,\n refresh_token: expandedUser.refresh_token,\n refresh_exp: expandedUser.refresh_exp\n };\n toast.success('Successfully logged in.');\n return user;\n } else {\n toast.error(response.data.error ? response.data.error : 'An Unknown Error has occurred');\n return null;\n }\n }).catch(error => {\n if (error.response === 401) {\n toast.error('Unauthorized');\n } else if (error.response === 429) {\n toast.error('Rate limited. Please try again shortly');\n } else {\n toast.error('Failed to connect');\n }\n\n return Promise.resolve();\n });\n};\n_c = PostLogin;\nexport const PostRefreshToken = refreshToken => {\n return axios.post(process.env.REACT_APP_API_URL + \"/api/v1/refresh\", {\n token: refreshToken\n }).then(response => {\n if (response.data.token) {\n let expandedUser = jwt(response.data.token);\n let user = {\n jwt: response.data.token,\n uuid: expandedUser.sub,\n exp: expandedUser.exp,\n username: expandedUser.username,\n admin: expandedUser.admin,\n mod: expandedUser.mod,\n refresh_token: expandedUser.refresh_token,\n refresh_exp: expandedUser.refresh_exp\n };\n return user;\n } else {\n toast.error(response.data.error ? response.data.error : 'An Unknown Error has occurred');\n return null;\n }\n }).catch(error => {\n if (error.response === 401) {\n toast.error('Unauthorized');\n } else if (error.response === 429) {\n toast.error('Rate limited. Please try again shortly');\n } else {\n toast.error('Failed to connect');\n }\n\n return Promise.resolve();\n });\n};\n_c2 = PostRefreshToken;\nexport const PostRegister = formValues => {\n return axios.post(process.env.REACT_APP_API_URL + \"/api/v1/register\", formValues).then(response => {\n if (response.data.message) {\n toast.success(response.data.message);\n return Promise.resolve();\n } else {\n toast.error(response.data.error ? response.data.error : 'An Unknown Error has occurred');\n return Promise.resolve();\n }\n }).catch(error => {\n handleErrorResp(error);\n return Promise.resolve();\n });\n};\n_c3 = PostRegister;\nexport const PostResetPassword = formValues => {\n return axios.post(process.env.REACT_APP_API_URL + \"/api/v1/resetpassword\", formValues).then(response => {\n if (response.data.message) {\n toast.success(response.data.message);\n return Promise.resolve();\n } else {\n toast.error(response.data.error ? response.data.error : 'An Unknown Error has occurred');\n return Promise.reject();\n }\n }).catch(error => {\n handleErrorResp(error);\n return Promise.resolve();\n });\n};\n_c4 = PostResetPassword;\nexport const sendPasswordReset = values => {\n return axios.post(process.env.REACT_APP_API_URL + \"/api/v1/sendreset\", values).then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const uploadImage = (values, type, uuid, history) => {\n return axios.post(process.env.REACT_APP_API_URL + \"/api/v1/\" + type + \"s/\" + uuid + \"/upload\", values, {\n headers: getHeaders()\n }).then(response => {\n if (response.data.message) {\n toast.success(response.data.message); // Hacky (:\n\n history.push(\"/\" + type + \"/\" + uuid);\n window.location.reload();\n return Promise.resolve();\n } else {\n toast.error(response.data.error ? response.data.error : 'An Unknown Error has occurred');\n return Promise.reject();\n }\n }).catch(error => {\n handleErrorResp(error);\n return Promise.resolve();\n });\n};\nexport const getStats = () => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/stats\").then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n}; // export const getRecentScrobblesForUser = (uuid) => {\n// return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/user/\" + uuid + \"/scrobbles\", { headers: getHeaders() })\n// .then((data) => {\n// return data.data;\n// }).catch((error) => {\n// return handleErrorResp(error)\n// });\n// };\n\nexport const getRecentScrobbles = () => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/recent\").then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const getConfigs = () => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/config\", {\n headers: getHeaders()\n }).then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const postConfigs = (values, toggle) => {\n if (toggle) {\n values.REGISTRATION_ENABLED = \"1\";\n } else {\n values.REGISTRATION_ENABLED = \"0\";\n }\n\n return axios.post(process.env.REACT_APP_API_URL + \"/api/v1/config\", values, {\n headers: getHeaders()\n }).then(data => {\n if (data.data && data.data.message) {\n toast.success(data.data.message);\n } else if (data.data && data.data.error) {\n toast.error(data.data.error);\n }\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const getProfile = userName => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/profile/\" + userName, {\n headers: getHeaders()\n }).then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const getUser = () => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/user\", {\n headers: getHeaders()\n }).then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const patchUser = values => {\n return axios.patch(process.env.REACT_APP_API_URL + \"/api/v1/user\", values, {\n headers: getHeaders()\n }).then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const validateResetPassword = tokenStr => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/user/\", {\n headers: getHeaders()\n }).then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const getSpotifyClientId = () => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/user/spotify\", {\n headers: getHeaders()\n }).then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const spotifyConnectionRequest = () => {\n return getSpotifyClientId().then(resp => {\n var scopes = 'user-read-recently-played user-read-currently-playing'; // Local, lets forward it to API\n\n let redirectUri = window.location.origin.toString() + \"/api/v1/link/spotify\"; // Stupid dev\n\n if (window.location.origin.toString() === \"http://localhost:3000\") {\n redirectUri = \"http://localhost:42069/api/v1/link/spotify\";\n }\n\n window.location = 'https://accounts.spotify.com/authorize' + '?response_type=code' + '&client_id=' + resp.token + '&scope=' + encodeURIComponent(scopes) + '&redirect_uri=' + encodeURIComponent(redirectUri) + '&state=' + getUserUuid();\n });\n};\nexport const spotifyDisonnectionRequest = () => {\n return axios.delete(process.env.REACT_APP_API_URL + \"/api/v1/user/spotify\", {\n headers: getHeaders()\n }).then(data => {\n toast.success(data.data.message);\n return true;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const navidromeConnectionRequest = values => {\n return axios.post(process.env.REACT_APP_API_URL + \"/api/v1/user/navidrome\", values, {\n headers: getHeaders()\n }).then(data => {\n toast.success(data.data.message);\n return true;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const navidromeDisonnectionRequest = () => {\n return axios.delete(process.env.REACT_APP_API_URL + \"/api/v1/user/navidrome\", {\n headers: getHeaders()\n }).then(data => {\n toast.success(data.data.message);\n return true;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const getServerInfo = () => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/serverinfo\").then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const getArtist = uuid => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/artists/\" + uuid).then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const getAlbum = uuid => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/albums/\" + uuid).then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const getTrack = uuid => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/tracks/\" + uuid).then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const getTopTracks = (uuid, days) => {\n let url = process.env.REACT_APP_API_URL + \"/api/v1/tracks/top/\" + uuid;\n\n if (days) {\n url = url + \"/\" + days;\n }\n\n return axios.get(url).then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const getArtistTracks = uuid => {\n let url = process.env.REACT_APP_API_URL + \"/api/v1/tracks/artist/\" + uuid;\n return axios.get(url).then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const getAlbumTracks = uuid => {\n let url = process.env.REACT_APP_API_URL + \"/api/v1/tracks/album/\" + uuid;\n return axios.get(url).then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const getTopArtists = (uuid, days) => {\n let url = process.env.REACT_APP_API_URL + \"/api/v1/artists/top/\" + uuid;\n\n if (days) {\n url = url + \"/\" + days;\n }\n\n return axios.get(url).then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const getTopUsersForTrack = uuid => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/tracks/\" + uuid + \"/top\").then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const getTopUsersForAlbum = uuid => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/albums/\" + uuid + \"/top\").then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\nexport const getTopUsersForArtist = uuid => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/artists/\" + uuid + \"/top\").then(data => {\n return data.data;\n }).catch(error => {\n return handleErrorResp(error);\n });\n};\n\nvar _c, _c2, _c3, _c4;\n\n$RefreshReg$(_c, \"PostLogin\");\n$RefreshReg$(_c2, \"PostRefreshToken\");\n$RefreshReg$(_c3, \"PostRegister\");\n$RefreshReg$(_c4, \"PostResetPassword\");","map":{"version":3,"sources":["/app/src/Api/index.js"],"names":["axios","jwt","toast","getHeaders","user","JSON","parse","localStorage","getItem","unixtime","Math","round","Date","getTime","exp","removeItem","window","location","reload","Authorization","getUserUuid","uuid","handleErrorResp","error","response","status","PostLogin","formValues","post","process","env","REACT_APP_API_URL","then","data","token","expandedUser","sub","username","admin","mod","refresh_token","refresh_exp","success","catch","Promise","resolve","PostRefreshToken","refreshToken","PostRegister","message","PostResetPassword","reject","sendPasswordReset","values","uploadImage","type","history","headers","push","getStats","get","getRecentScrobbles","getConfigs","postConfigs","toggle","REGISTRATION_ENABLED","getProfile","userName","getUser","patchUser","patch","validateResetPassword","tokenStr","getSpotifyClientId","spotifyConnectionRequest","resp","scopes","redirectUri","origin","toString","encodeURIComponent","spotifyDisonnectionRequest","delete","navidromeConnectionRequest","navidromeDisonnectionRequest","getServerInfo","getArtist","getAlbum","getTrack","getTopTracks","days","url","getArtistTracks","getAlbumTracks","getTopArtists","getTopUsersForTrack","getTopUsersForAlbum","getTopUsersForArtist"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,GAAP,MAAgB,YAAhB;AACA,SAASC,KAAT,QAAsB,gBAAtB;;AAEA,SAASC,UAAT,GAAsB;AACpB,QAAMC,IAAI,GAAGC,IAAI,CAACC,KAAL,CAAWC,YAAY,CAACC,OAAb,CAAqB,MAArB,CAAX,CAAb;;AAEA,MAAIJ,IAAI,IAAIA,IAAI,CAACH,GAAj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,CAAC4D,GAAN,CAAU/B,OAAO,CAACC,GAAR,CAAYC,iBAAZ,GAAgC,kBAAhC,GAAqDV,IAArD,GAA4D,MAAtE,EAA8EW,IAA9E,CACJC,IAAD,IAAU;AACR,WAAOA,IAAI,CAACA,IAAZ;AACH,GAHM,EAGJU,KAHI,CAGGpB,KAAD,IAAW;AAClB,WAAOD,eAAe,CAACC,KAAD,CAAtB;AACD,GALM,CAAP;AAMD,CAPM","sourcesContent":["import axios from 'axios';\nimport jwt from 'jwt-decode'\nimport { toast } from 'react-toastify';\n\nfunction getHeaders() {\n const user = JSON.parse(localStorage.getItem('user'));\n\n if (user && user.jwt) {\n var unixtime = Math.round((new Date()).getTime() / 1000);\n if (user.exp < unixtime) {\n // Trigger refresh\n localStorage.removeItem('user');\n window.location.reload();\n // toast.warning(\"Session expired. Please log in again\")\n // window.location.reload();\n return {};\n }\n\n return { Authorization: 'Bearer ' + user.jwt };\n } else {\n return {};\n }\n}\n\nfunction getUserUuid() {\n // TODO: move this to use Context values instead.\n const user = JSON.parse(localStorage.getItem('user'));\n\n if (user && user.uuid) {\n return user.uuid\n } else {\n return '';\n }\n}\n\nfunction handleErrorResp(error) {\n if (error.response) {\n if (error.response.status === 401) {\n toast.error('Unauthorized')\n } else if (error.response.status === 429) {\n toast.error('Rate limited. Please try again shortly')\n } else {\n toast.error('An unknown error has occurred');\n }\n } else {\n toast.error('Failed to connect to API');\n }\n return {};\n}\n\nexport const PostLogin = (formValues) => {\n return axios.post(process.env.REACT_APP_API_URL + \"/api/v1/login\", formValues)\n .then((response) => {\n if (response.data.token) {\n let expandedUser = jwt(response.data.token)\n let user = {\n jwt: response.data.token,\n uuid: expandedUser.sub,\n exp: expandedUser.exp,\n username: expandedUser.username,\n admin: expandedUser.admin,\n mod: expandedUser.mod,\n refresh_token: expandedUser.refresh_token,\n refresh_exp: expandedUser.refresh_exp,\n }\n\n toast.success('Successfully logged in.');\n return user;\n } else {\n toast.error(response.data.error ? response.data.error: 'An Unknown Error has occurred');\n return null\n }\n }).catch((error) => {\n if (error.response === 401) {\n toast.error('Unauthorized')\n } else if (error.response === 429) {\n toast.error('Rate limited. Please try again shortly')\n } else {\n toast.error('Failed to connect');\n }\n return Promise.resolve();\n });\n};\n\nexport const PostRefreshToken = (refreshToken) => {\n return axios.post(process.env.REACT_APP_API_URL + \"/api/v1/refresh\", {token: refreshToken})\n .then((response) => {\n if (response.data.token) {\n let expandedUser = jwt(response.data.token)\n let user = {\n jwt: response.data.token,\n uuid: expandedUser.sub,\n exp: expandedUser.exp,\n username: expandedUser.username,\n admin: expandedUser.admin,\n mod: expandedUser.mod,\n refresh_token: expandedUser.refresh_token,\n refresh_exp: expandedUser.refresh_exp,\n }\n\n return user;\n } else {\n toast.error(response.data.error ? response.data.error: 'An Unknown Error has occurred');\n return null\n }\n }).catch((error) => {\n if (error.response === 401) {\n toast.error('Unauthorized')\n } else if (error.response === 429) {\n toast.error('Rate limited. Please try again shortly')\n } else {\n toast.error('Failed to connect');\n }\n return Promise.resolve();\n });\n};\n\n\nexport const PostRegister = (formValues) => {\n return axios.post(process.env.REACT_APP_API_URL + \"/api/v1/register\", formValues)\n .then((response) => {\n if (response.data.message) {\n toast.success(response.data.message);\n\n return Promise.resolve();\n } else {\n toast.error(response.data.error ? response.data.error: 'An Unknown Error has occurred');\n\n return Promise.resolve();\n }\n }).catch((error) => {\n handleErrorResp(error)\n return Promise.resolve();\n });\n};\n\nexport const PostResetPassword = (formValues) => {\n return axios.post(process.env.REACT_APP_API_URL + \"/api/v1/resetpassword\", formValues)\n .then((response) => {\n if (response.data.message) {\n toast.success(response.data.message);\n\n return Promise.resolve();\n } else {\n toast.error(response.data.error ? response.data.error: 'An Unknown Error has occurred');\n\n return Promise.reject();\n }\n }).catch((error) => {\n handleErrorResp(error)\n return Promise.resolve();\n });\n};\n\nexport const sendPasswordReset = (values) => {\n return axios.post(process.env.REACT_APP_API_URL + \"/api/v1/sendreset\", values).then(\n (data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n};\n\nexport const uploadImage = (values, type, uuid, history) => {\n return axios.post(process.env.REACT_APP_API_URL + \"/api/v1/\"+type+\"s/\"+uuid+\"/upload\", values, { headers: getHeaders() })\n .then((response) => {\n if (response.data.message) {\n toast.success(response.data.message);\n \n // Hacky (:\n history.push(\"/\"+type+\"/\"+uuid);\n window.location.reload();\n\n\n return Promise.resolve();\n } else {\n toast.error(response.data.error ? response.data.error: 'An Unknown Error has occurred');\n\n return Promise.reject();\n }\n }).catch((error) => {\n handleErrorResp(error)\n return Promise.resolve();\n });\n};\n\nexport const getStats = () => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/stats\").then(\n (data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n};\n\n// export const getRecentScrobblesForUser = (uuid) => {\n// return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/user/\" + uuid + \"/scrobbles\", { headers: getHeaders() })\n// .then((data) => {\n// return data.data;\n// }).catch((error) => {\n// return handleErrorResp(error)\n// });\n// };\n\nexport const getRecentScrobbles = () => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/recent\")\n .then((data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n};\n\nexport const getConfigs = () => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/config\", { headers: getHeaders() })\n .then((data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n};\n\nexport const postConfigs = (values, toggle) => {\n if (toggle) {\n values.REGISTRATION_ENABLED = \"1\"\n } else {\n values.REGISTRATION_ENABLED = \"0\"\n }\n\n return axios.post(process.env.REACT_APP_API_URL + \"/api/v1/config\", values, { headers: getHeaders() })\n .then((data) => {\n if (data.data && data.data.message) {\n toast.success(data.data.message);\n } else if (data.data && data.data.error) {\n toast.error(data.data.error);\n }\n }).catch((error) => {\n return handleErrorResp(error)\n });\n};\n\nexport const getProfile = (userName) => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/profile/\" + userName, { headers: getHeaders() })\n .then((data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n};\n\nexport const getUser = () => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/user\", { headers: getHeaders() })\n .then((data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n};\n\nexport const patchUser = (values) => {\n return axios.patch(process.env.REACT_APP_API_URL + \"/api/v1/user\", values, { headers: getHeaders() })\n .then((data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n};\n\nexport const validateResetPassword = (tokenStr) => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/user/\", { headers: getHeaders() })\n .then((data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n};\n\nexport const getSpotifyClientId = () => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/user/spotify\", { headers: getHeaders() })\n .then((data) => {\n return data.data\n }).catch((error) => {\n return handleErrorResp(error)\n });\n}\n\nexport const spotifyConnectionRequest = () => {\n return getSpotifyClientId().then((resp) => {\n var scopes = 'user-read-recently-played user-read-currently-playing';\n\n // Local, lets forward it to API\n let redirectUri = window.location.origin.toString()+ \"/api/v1/link/spotify\";\n\n // Stupid dev\n if (window.location.origin.toString() === \"http://localhost:3000\") {\n redirectUri = \"http://localhost:42069/api/v1/link/spotify\"\n }\n\n window.location = 'https://accounts.spotify.com/authorize' +\n '?response_type=code' +\n '&client_id=' + resp.token +\n '&scope=' + encodeURIComponent(scopes) +\n '&redirect_uri=' + encodeURIComponent(redirectUri) +\n '&state=' + getUserUuid();\n })\n};\n\nexport const spotifyDisonnectionRequest = () => {\n return axios.delete(process.env.REACT_APP_API_URL + \"/api/v1/user/spotify\", { headers: getHeaders() })\n .then((data) => {\n toast.success(data.data.message);\n return true\n }).catch((error) => {\n return handleErrorResp(error)\n });\n}\n\nexport const navidromeConnectionRequest = (values) => {\n return axios.post(process.env.REACT_APP_API_URL + \"/api/v1/user/navidrome\", values, { headers: getHeaders() })\n .then((data) => {\n toast.success(data.data.message);\n return true\n }).catch((error) => {\n return handleErrorResp(error)\n });\n};\n\nexport const navidromeDisonnectionRequest = () => {\n return axios.delete(process.env.REACT_APP_API_URL + \"/api/v1/user/navidrome\", { headers: getHeaders() })\n .then((data) => {\n toast.success(data.data.message);\n return true\n }).catch((error) => {\n return handleErrorResp(error)\n });\n}\n\nexport const getServerInfo = () => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/serverinfo\")\n .then((data) => {\n return data.data\n }).catch((error) => {\n return handleErrorResp(error)\n });\n}\n\nexport const getArtist = (uuid) => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/artists/\" + uuid).then(\n (data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n};\n\nexport const getAlbum = (uuid) => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/albums/\" + uuid).then(\n (data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n};\n\nexport const getTrack = (uuid) => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/tracks/\" + uuid).then(\n (data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n};\n\nexport const getTopTracks = (uuid, days) => {\n let url = process.env.REACT_APP_API_URL + \"/api/v1/tracks/top/\" + uuid\n if (days) {\n url = url + \"/\" + days\n }\n\n return axios.get(url).then(\n (data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n}\n\nexport const getArtistTracks = (uuid) => {\n let url = process.env.REACT_APP_API_URL + \"/api/v1/tracks/artist/\" + uuid\n\n return axios.get(url).then(\n (data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n}\n\nexport const getAlbumTracks = (uuid) => {\n let url = process.env.REACT_APP_API_URL + \"/api/v1/tracks/album/\" + uuid\n\n return axios.get(url).then(\n (data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n}\n\nexport const getTopArtists = (uuid, days) => {\n let url = process.env.REACT_APP_API_URL + \"/api/v1/artists/top/\" + uuid\n if (days) {\n url = url + \"/\" + days\n }\n return axios.get(url).then(\n (data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n}\n\nexport const getTopUsersForTrack = (uuid) => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/tracks/\" + uuid + \"/top\").then(\n (data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n}\n\nexport const getTopUsersForAlbum = (uuid) => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/albums/\" + uuid + \"/top\").then(\n (data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n}\n\nexport const getTopUsersForArtist = (uuid) => {\n return axios.get(process.env.REACT_APP_API_URL + \"/api/v1/artists/\" + uuid + \"/top\").then(\n (data) => {\n return data.data;\n }).catch((error) => {\n return handleErrorResp(error)\n });\n}"]},"metadata":{},"sourceType":"module"}