diff options
author | RaindropsSys <contact@minteck.org> | 2023-06-22 23:06:12 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-06-22 23:06:12 +0200 |
commit | 23563c7188e089929b60f9e10721c6fc43a220ff (patch) | |
tree | edfe2b009c82900d4ac27db02222d2f68dcad846 /includes/external/school/node_modules/pronote-api/src/axioRequest.js | |
parent | 7a7a49332df7c852abbaa33c7e8e87f93d064d61 (diff) | |
download | pluralconnect-23563c7188e089929b60f9e10721c6fc43a220ff.tar.gz pluralconnect-23563c7188e089929b60f9e10721c6fc43a220ff.tar.bz2 pluralconnect-23563c7188e089929b60f9e10721c6fc43a220ff.zip |
Updated 15 files, added includes/maintenance/deleteUnusedAssets.php and deleted 4944 files (automated)
Diffstat (limited to 'includes/external/school/node_modules/pronote-api/src/axioRequest.js')
-rw-r--r-- | includes/external/school/node_modules/pronote-api/src/axioRequest.js | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/includes/external/school/node_modules/pronote-api/src/axioRequest.js b/includes/external/school/node_modules/pronote-api/src/axioRequest.js deleted file mode 100644 index 3e625c2..0000000 --- a/includes/external/school/node_modules/pronote-api/src/axioRequest.js +++ /dev/null @@ -1,86 +0,0 @@ -const axios = require('axios'); - -async function axioRequest({ url, body, data, method = 'GET', binary, jar = null }) { - let userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0'; - if (url.includes('teleservices.ac-nancy-metz.fr')) { - userAgent = 'FuckTheUselessProtection/1.0'; - } - - const params = encodeParams(data); - const content = { - url, - method: method.toLowerCase(), - headers: { - 'User-Agent': userAgent, - 'Content-Type': body !== undefined - ? 'application/json' - : (params !== '' && method !== 'GET' ? 'application/x-www-form-urlencoded' : ''), - 'Cookie': encodeCookies(jar) - }, - maxRedirects: 0, - validateStatus(status) { - return status === 401 || (status >= 200 && status <= 302) - } - }; - - if (binary) { - content.responseType = 'arraybuffer'; - } - - if (params) { - if (method.toUpperCase() === 'GET') { - content.url += '?' + params; - } else { - content.data = params; - } - } else if (body) { - content.data = body; - } - const response = await axios(content) - - if (response.headers['set-cookie'] && jar !== null) { - await updateCookies(response, jar, url); - } - - return response; -} - -function updateCookies(response, jar, url) { - return new Promise((accept, reject) => { - response.headers['set-cookie'].forEach(cookie => { - jar.setCookie(cookie, url, err => (err ? reject(err) : accept())); - }); - }); -} - -function encodeCookies(jar) { - if (!jar) { - return ''; - } - - let cookies = ''; - jar.toJSON().cookies.forEach(cookie => cookies += cookie.key + '=' + cookie.value + '; '); - - if (cookies.length !== 0) { - cookies = cookies.substring(0, cookies.length - 2); - } - - return cookies; -} - -function encodeParams(data) { - if (!data) { - return ''; - } - - let params = ''; - for (const k of Object.keys(data)) { - const v = data[k]; - params += `${k}=${encodeURIComponent(v)}&` - } - - return params.substring(0, params.length - 1) -} - - -module.exports = axioRequest |