diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-03-02 16:51:05 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-03-02 16:51:05 +0700 |
| commit | d336735a91133cc3f1cf6f67ba2ac29f0985fd2e (patch) | |
| tree | f64a5c6de6e0ea015952ae028dca115077cffa45 /src2/core/utils/apiOdoo.js | |
| parent | 074edfe4e51efd3b4a44dc7fe6e1284c9c560501 (diff) | |
delete src2
Diffstat (limited to 'src2/core/utils/apiOdoo.js')
| -rw-r--r-- | src2/core/utils/apiOdoo.js | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/src2/core/utils/apiOdoo.js b/src2/core/utils/apiOdoo.js deleted file mode 100644 index 4d0adae3..00000000 --- a/src2/core/utils/apiOdoo.js +++ /dev/null @@ -1,44 +0,0 @@ -import { getCookie, setCookie } from 'cookies-next'; -import axios from 'axios'; -import { getAuth } from './auth'; - -const renewToken = async () => { - let token = await axios.get(process.env.SELF_HOST + '/api/token'); - setCookie('token', token.data); - return token.data; -}; - -const getToken = async () => { - let token = getCookie('token'); - if (token == undefined) token = await renewToken(); - return token; -}; - -let connectionTry = 0; -const apiOdoo = async (method, url, data = {}, headers = {}) => { - try { - connectionTry++; - let token = await getToken(); - let axiosParameter = { - method, - url: process.env.ODOO_HOST + url, - headers: {'Authorization': token, ...headers} - } - const auth = getAuth(); - - if (auth) axiosParameter.headers['Token'] = auth.token; - if (method.toUpperCase() == 'POST') axiosParameter.headers['Content-Type'] = 'application/x-www-form-urlencoded'; - if (Object.keys(data).length > 0) axiosParameter.data = new URLSearchParams(Object.entries(data)).toString(); - - let res = await axios(axiosParameter); - if (res.data.status.code == 401 && connectionTry < 15) { - await renewToken(); - return apiOdoo(method, url, data, headers); - } - return res.data.result || []; - } catch (error) { - console.log(error) - } -} - -export default apiOdoo;
\ No newline at end of file |
