This repository was archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
113 lines (91 loc) · 3.04 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const config = require("./config.json");
const fetch = require("node-fetch");
let token = "";
let schoolId = "";
exports.entClient = class entClient {
async loginByCredentials(username, password) {
const connexion = await sendRequest(`activation/${username}/${password}`);
if (!connexion.success) return false;
token = connexion.authtoken;
return true;
}
async loginByToken(givenToken) {
token = givenToken;
try {
const info = await sendRequest("infoutilisateur");
if (!info.errmsg) {
schoolId = info.idEtablissementSelectionne;
return true;
}
else return false;
} catch {
return false;
}
}
loginByTokenWithoutVerification(givenToken, givenSchoolId) {
token = givenToken;
schoolId = givenSchoolId;
}
getToken() {
return token;
}
async getNews() {
return await sendRequest(`actualites/idetablissement/${schoolId}`);
}
async getNewsById(id) {
return await sendRequest(`mobilite/contenuArticle/article/${id}`);
}
async getInfo() {
return await sendRequest("infoutilisateur");
}
async getWork() {
return await sendRequest(`travailAFaire/idetablissement/${schoolId}`);
}
async getWorkById(uIdSeance, uId) {
return await sendRequest(`contenuActivite/idetablissement/${schoolId}/${uIdSeance}/${uId}`);
}
async getCalendar() {
return await sendRequest(`calendrier/idetablissement/${schoolId}`);
}
async getMessage() {
return await sendRequest("messagerie/boiteReception");
}
async getUnreadMessage() {
const request = await sendRequest("messagerie/info");
return request.nbMessagesNonLus;
}
async getLack() {
return await sendRequest(`consulterAbsences/idetablissement/${schoolId}`);
}
async getGrade() {
return await sendRequest(`consulterNotes/idetablissement/${schoolId}`);
}
async getTranscript() {
return await sendRequest(`consulterReleves/idetablissement/${schoolId}`);
}
async logout() {
const logout = await sendRequest("desactivation");
return logout.success;
}
};
async function sendRequest(path) {
return await fetch(`https://mobilite.${config.REMOTE_ENT_API}/mobilite/${path}/?_=${Date.now()}`, {
headers: {
Accept: "application/json, text/javascript, */*; q=0.01",
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148",
"Accept-Language": "fr-fr",
"X-Kdecole-Auth": token,
"X-Kdecole-Vers": "3.7.10",
cookie: "SERVERID=REDACTED-prod-web14"
}
})
.then(res => res.json())
.catch(() => {
// Default Object to avoid errors from the API file
return {
success: false,
errmsg: false,
nbMessagesNonLus: false
}
});
};