Skip to content

Commit

Permalink
Merge branch 'working' into feat/last-grades
Browse files Browse the repository at this point in the history
  • Loading branch information
Truiteseche committed Mar 2, 2024
2 parents c79727b + 2aa2022 commit 2bedeba
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 30 deletions.
50 changes: 29 additions & 21 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function consoleLogEDPLogo() {
consoleLogEDPLogo();

const currentEDPVersion = "0.2.5";
const apiVersion = "4.51.1";
const apiVersion = "4.52.1";

// secret webhooks
const carpeConviviale = "CARPE_CONVIVIALE_WEBHOOK_URL";
Expand Down Expand Up @@ -1042,17 +1042,18 @@ export default function App() {
const options = {
body: "data=" + JSON.stringify(payload),
method: "POST",
signal: controller.signal
signal: controller.signal,
referrerPolicy: "no-referrer"
}

const messages = {
submitButtonText: "",
submitErrorMessage: ""
};

// fetch(`https://api.ecoledirecte.com/v3/login.awp?v=${apiVersion}`, options)
// fetch(`https://api.ecole-directe.plus/proxy?url=https://api.ecoledirecte.com/v3/login.awp?v=${apiVersion}`, options)
fetch(getProxiedURL(`https://api.ecoledirecte.com/v3/login.awp?v=${apiVersion}`), options)
fetch(getProxiedURL(`https://api.ecoledirecte.com/v3/login.awp?v=${apiVersion}`, true), options)
// fetch(`https://api.ecoledirecte.com/v3/login.awp?v=${apiVersion}`, options)
// fetch(`https://server.ecoledirecte.neptunium.fr/api/user/login`, options)
.then((response) => response.json())
.then((response) => {
Expand Down Expand Up @@ -1141,15 +1142,17 @@ export default function App() {
anneeScolaire: getUserSettingValue("isSchoolYearEnabled") ? getUserSettingValue("schoolYear").join("-") : ""
}

fetch(getProxiedURL(`https://api.ecoledirecte.com/v3/eleves/${accountsListState[activeAccount].id}/timeline.awp?verbe=get&v=${apiVersion}`),
fetch(getProxiedURL(`https://api.ecoledirecte.com/v3/eleves/${accountsListState[activeAccount].id}/timeline.awp?verbe=get&v=${apiVersion}`, true),
// fetch(`https://api.ecoledirecte.com/v3/eleves/${accountsListState[activeAccount].id}/timeline.awp?verbe=get&v=${apiVersion}`,
{
method: "POST",
headers: {
"user-agent": navigator.userAgent,
// "user-agent": navigator.userAgent,
"x-token": tokenState,
},
body: `data=${JSON.stringify(data)}`,
signal: controller.signal
signal: controller.signal,
referrerPolicy: "no-referrer"
})
.then((response) => response.json())
.then((response) => {
Expand Down Expand Up @@ -1190,18 +1193,19 @@ export default function App() {
}
return await fetch(
// `https://raspi.ecole-directe.plus:3000/proxy?url=https://api.ecoledirecte.com/v3/telechargement.awp?verbe=get&fichierId=${file}&leTypeDeFichier=NODEVOIR&idDevoir=${id}&v=${apiVersion}`,
getProxiedURL(`https://api.ecoledirecte.com/v3/telechargement.awp?verbe=get&fichierId=${file}&leTypeDeFichier=NODEVOIR&idDevoir=${id}&v=${apiVersion}`),
getProxiedURL(`https://api.ecoledirecte.com/v3/telechargement.awp?verbe=get&fichierId=${file}&leTypeDeFichier=NODEVOIR&idDevoir=${id}&v=${apiVersion}`, true),
// `https://api.ecoledirecte.com/v3/telechargement.awp?verbe=get&fichierId=${file}&leTypeDeFichier=NODEVOIR&idDevoir=${id}&v=${apiVersion}`,
// `https://raspi.ecole-directe.plus:3000/proxy?url=https://api.ecoledirecte.com/v3/telechargement.awp?verbe=get&fichierId=${file}&leTypeDeFichier=NODEVOIR&idDevoir=${id}&v=${apiVersion}`,
{
method: "POST",
headers: {
"user-agent": navigator.userAgent,
// "user-agent": navigator.userAgent,
"x-token": tokenState
},
cors: "no-cors",
body: `data=${JSON.stringify(data)}`,
signal: controller.signal,
redirect: 'follow'
referrerPolicy: "no-referrer"
},
)
.then(response => response.blob())
Expand All @@ -1222,25 +1226,25 @@ export default function App() {
abortControllers.current.push(controller);
const userId = activeAccount;
const data = {
anneeScolaire: getUserSettingValue("isSchoolYearEnabled") ? getUserSettingValue("schoolYear").join("-") : ""
anneeScolaire: getUserSettingValue("isSchoolYearEnabled") ? getUserSettingValue("schoolYear").join("-") : "",
// token: tokenState
}
// await new Promise(resolve => setTimeout(resolve, 5000)); // timeout de 1.5s le fetch pour les tests des content-loaders
fetch(
// `https://api.ecoledirecte.com/v3/eleves/${accountsListState[userId].id}/notes.awp?verbe=get&v=${apiVersion}`,
// `https://api.ecole-directe.plus/proxy?url=https://api.ecoledirecte.com/v3/eleves/${accountsListState[userId].id}/notes.awp?verbe=get&v=${apiVersion}`,
getProxiedURL(`https://api.ecoledirecte.com/v3/eleves/${accountsListState[userId].id}/notes.awp?verbe=get&v=${apiVersion}`),
getProxiedURL(`https://api.ecoledirecte.com/v3/eleves/${accountsListState[userId].id}/notes.awp?verbe=get&v=${apiVersion}`, true),
// `https://api.ecoledirecte.com/v3/eleves/${accountsListState[userId].id}/notes.awp?verbe=get&v=${apiVersion}`,
// `https://server.ecoledirecte.neptunium.fr/api/user/notes/${accountsListState[userId].id}`,
{
method: "POST",
headers: {
"user-agent": navigator.userAgent,
// "user-agent": navigator.userAgent,
"x-token": tokenState
// "Content-Type": "application/json"
},
body: `data=${JSON.stringify(data)}`,
// body: JSON.stringify(data),
signal: controller.signal
signal: controller.signal,
referrerPolicy: "no-referrer",
},
)
.then((response) => response.json())
Expand Down Expand Up @@ -1291,15 +1295,17 @@ export default function App() {
anneeScolaire: getUserSettingValue("isSchoolYearEnabled") ? getUserSettingValue("schoolYear").join("-") : ""
}

fetch(getProxiedURL(`https://api.ecoledirecte.com/v3/eleves/${accountsListState[activeAccount].id}/viescolaire.awp?verbe=get&v=${apiVersion}`),
fetch(getProxiedURL(`https://api.ecoledirecte.com/v3/eleves/${accountsListState[activeAccount].id}/viescolaire.awp?verbe=get&v=${apiVersion}`, true),
// fetch(`https://api.ecoledirecte.com/v3/eleves/${accountsListState[activeAccount].id}/viescolaire.awp?verbe=get&v=${apiVersion}`,
{
method: "POST",
headers: {
"user-agent": navigator.userAgent,
// "user-agent": navigator.userAgent,
"x-token": tokenState,
},
body: `data=${JSON.stringify(data)}`,
signal: controller.signal
signal: controller.signal,
referrerPolicy: "no-referrer"
})
.then((response) => response.json())
.then((response) => {
Expand Down Expand Up @@ -1337,14 +1343,16 @@ export default function App() {
const data = {
libelle: name,
}
fetch(getProxiedURL("https://api.ecoledirecte.com/v3/messagerie/classeurs.awp?verbe=post%26v=4.46.0"),
fetch(getProxiedURL("https://api.ecoledirecte.com/v3/messagerie/classeurs.awp?verbe=post%26v=4.52.0", true),
// fetch("https://api.ecoledirecte.com/v3/messagerie/classeurs.awp?verbe=post%26v=4.52.0",
{
method: "POST",
headers: {
"user-agent": navigator.userAgent,
// "user-agent": navigator.userAgent,
"x-token": tokenState,
},
body: `data=${JSON.stringify(data)}`,
referrerPolicy: "no-referrer"
},
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Feedback/FeedbackForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export default function FeedbackForm({ activeUser, carpeConviviale, onSubmit=()
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
content: `botActions:[VERIFY],${allowSharing ? "" : "[DISABLE_VERIFY]"}`,
content: `botActions:[VERIFY],${allowSharing ? "" : "[DISABLE_VERIFY]"} <@1192136509567016990>`, // allow us to handle feedback sharing on our discord server
embeds: [
{
color: parseInt("0x" + color),
Expand Down
2 changes: 1 addition & 1 deletion src/components/Login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function Login({ keepLoggedIn, setKeepLoggedIn, fetchLogin, logou
En vous connectant, vous confirmez avoir lu et accepté notre <Link to="#policy" replace={true} className="policy-link" id="legal-notice">Politique de confidentialité et Conditions d'utilisation</Link>.
</p>
<p className="temp-disclaimer" id="proxy-error-notification">
Nous rencontrons quelques problèmes liés à l'API d'EcoleDirecte. Si le chargement dure, ne perdez pas votre temps à attendre la fin (elle n'arrivera pas). Nous travaillons activement sur ce problème, veuillez revenir dans quelques heures/jours.
Nous rencontrons quelques problèmes liés à l'API d'EcoleDirecte. Nous travaillons activement sur ce problème, veuillez revenir dans quelques heures/jours.
</p>
{location.hash === "#policy" && <Policy onCloseNavigateURL={""} />}
<EDPVersion currentEDPVersion={currentEDPVersion} />
Expand Down
12 changes: 8 additions & 4 deletions src/components/generic/UserInputs/NumberInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default function NumberInput({ min, max, value, onChange, active=true, di
const intervalId = useRef(0);
const initialValue = useRef(value);
const valueRef = useRef(value);
const minMaxRef = useRef([min, max]);

const numberInputRef = useRef(null);
useEffect(() => {
Expand Down Expand Up @@ -56,7 +57,10 @@ export default function NumberInput({ min, max, value, onChange, active=true, di
}, [value])

useEffect(() => {
changeValueBy(0);
if (min !== minMaxRef.current[0] || max !== minMaxRef.current[1]) {
changeValueBy(0);
minMaxRef.current = [min, max];
}
}, [min, max])

const handleButtonPress = (delta) => {
Expand All @@ -65,13 +69,13 @@ export default function NumberInput({ min, max, value, onChange, active=true, di
const TICK_DURACTION = 50;
timeoutId.current = setTimeout(() => {
intervalId.current = setInterval(changeValueBy, TICK_DURACTION, delta);
} , SLEEP_DURATION)
}, SLEEP_DURATION)
document.addEventListener("mouseup", clearAutoChange);
document.addEventListener("touchend", clearAutoChange);
}

const changeValueBy = (delta) => {
function test(delta) {
function checkBounds(delta) {
let newValue = parseFloat(valueRef.current) + delta;
if (newValue < min) {
newValue = min;
Expand All @@ -80,7 +84,7 @@ export default function NumberInput({ min, max, value, onChange, active=true, di
}
return newValue
}
submitValue(test(delta));
submitValue(checkBounds(delta));
}

const clearAutoChange = () => {
Expand Down
33 changes: 30 additions & 3 deletions src/utils/requests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@

export function getProxiedURL(url) {
const proxyURL = "https://raspi.ecole-directe.plus:3000/proxy?url=";
return proxyURL + encodeURIComponent(url);
function isWeekdayAndBusinessHours() {
const now = new Date();
const day = now.getDay();
const hour = now.getHours();
const minutes = now.getMinutes();

// Check if it's a weekday (Monday=1 to Friday=5)
const isWeekday = day >= 1 && day <= 5;

// Convert the current hour and minutes to minutes to make comparison easier
const currentMinutes = hour * 60 + minutes;

// Start of day (8:00 AM) and end of day (5:30 PM) in minutes
const startOfDay = 8 * 60;
const endOfDay = 17 * 60 + 30;

// Check if the current time is between 8:00 AM and 5:30 PM
const isBusinessHours = currentMinutes >= startOfDay && currentMinutes <= endOfDay;

return isWeekday && isBusinessHours;
}


export function getProxiedURL(url, bait = false) {
const proxyURL = "https://api.ecole-directe.plus/proxy?url=";
if (!bait || (isWeekdayAndBusinessHours() && location.hostname === "ecole-directe.plus")) {
return proxyURL + encodeURIComponent(url);
} else {
return url;
}
}

0 comments on commit 2bedeba

Please sign in to comment.