diff options
author | Minteck <contact@minteck.org> | 2023-01-10 14:54:04 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2023-01-10 14:54:04 +0100 |
commit | 99c1d9af689e5325f3cf535c4007b3aeb8325229 (patch) | |
tree | e663b3c2ebdbd67c818ac0c5147f0ce1d2463cda /alarm/node_modules/pronote-api/src/session.js | |
parent | 9871b03912fc28ad38b4037ebf26a78aa937baba (diff) | |
download | pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.gz pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.bz2 pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.zip |
Update - This is an automated commit
Diffstat (limited to 'alarm/node_modules/pronote-api/src/session.js')
-rw-r--r-- | alarm/node_modules/pronote-api/src/session.js | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/alarm/node_modules/pronote-api/src/session.js b/alarm/node_modules/pronote-api/src/session.js deleted file mode 100644 index 6804d17..0000000 --- a/alarm/node_modules/pronote-api/src/session.js +++ /dev/null @@ -1,84 +0,0 @@ -const { initCipher } = require('./cipher'); -const getAccountType = require('./accounts'); - -const timetable = require('./fetch/timetable'); -const marks = require('./fetch/marks'); -const evaluations = require('./fetch/evaluations'); -const absences = require('./fetch/absences'); -const infos = require('./fetch/infos'); -const contents = require('./fetch/contents'); -const homeworks = require('./fetch/homeworks'); -const menu = require('./fetch/menu'); -const files = require('./fetch/files'); - -const keepAlive = require('./fetch/pronote/keepAlive'); -const logout = require('./fetch/pronote/logout'); - -const DEFAULT_KEEP_ALIVE_RATE = 120; // In seconds. 120 is the Pronote default 'Presence' request rate. -const GENERAL_REQUESTS = { - keepAlive, logout -}; -const REQUESTS = { - timetable, marks, evaluations, absences, contents, - infos, homeworks, menu, files -}; - -class PronoteSession -{ - constructor({ serverURL, sessionID, type, disableAES, disableCompress, keyModulus, keyExponent }) - { - this.id = ~~sessionID; - this.server = serverURL; - this.type = typeof type === 'string' ? getAccountType(type) : type; - - this.disableAES = disableAES; - this.disableCompress = disableCompress; - - initCipher(this, keyModulus, keyExponent); - - this.request = -1; - this.isKeptAlive = false; - - for (const [req, method] of Object.entries(GENERAL_REQUESTS)) { - this[req] = () => method(this); - } - for (const [req, method] of Object.entries(REQUESTS)) { - this[req] = (...args) => callRequest(method, this, args); - } - } - - setKeepAlive(enabled, onError, rate = DEFAULT_KEEP_ALIVE_RATE) - { - if (enabled === this.isKeptAlive) { - return; - } - - if (enabled) { - this.interval = setInterval(() => { - this.keepAlive().catch(err => { - this.setKeepAlive(false); - if (onError) { - onError(err); - } - }); - }, rate * 1000); - } else { - clearInterval(this.interval); - } - - this.isKeptAlive = enabled; - } -} - -function callRequest(method, session, args) -{ - switch (session.type.name) - { - case 'student': - return method(session, session.user, ...args); - default: - return method(session, ...args); - } -} - -module.exports = PronoteSession; |