Skip to content

Commit 559eee7

Browse files
committed
Update to support eduprox v0.2.0
1 parent 0da36b3 commit 559eee7

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

js/index.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,21 +637,34 @@ function intoText(obj) {
637637

638638
function getScheduleJSON(className, week, weekDay) {
639639
return new Promise(async (resolve, reject) => {
640-
let renderKeyResp, classGUID;
640+
let renderKeyResp;
641+
let selectionSignatureResp;
641642

642643
try {
643644
const resp = await Promise.all([
644645
fetchRenderKeyFromAPI(),
645-
getClassGUIDByName(className)
646+
fetchSignatureFromAPI(className)
646647
]);
647648

648649
renderKeyResp = resp[0];
649-
classGUID = resp[1];
650+
selectionSignatureResp = resp[1];
650651
} catch (error) {
651652
return reject(error);
652653
}
653654

654655
const renderKey = renderKeyResp.data.key;
656+
const selectionSignature = selectionSignatureResp.data.signature;
657+
658+
const springAutumnSwitchoverWeek = 25;
659+
const currentYear = DATE.getFullYear();
660+
const selectedYear =
661+
DATE.getWeek() > springAutumnSwitchoverWeek &&
662+
week < springAutumnSwitchoverWeek ?
663+
currentYear + 1 : currentYear;
664+
// I'll explain myself:
665+
// If we're in Autumn term, add one year to current year if requesting
666+
// schedule for Spring term. I did it this way since you probably don't
667+
// want to see last year's Spring term during Autumn term.
655668

656669
APIFetch(SCHEDULE_API_PREFIX + "schedule", {
657670
method: "POST",
@@ -660,10 +673,11 @@ function getScheduleJSON(className, week, weekDay) {
660673
},
661674
body: "{\"render_key\":\"" + renderKey +
662675
"\",\"unit_guid\":\"" + BERZAN_UNIT_GUID +
663-
"\",\"selection_signature\":\"" + classGUID +
676+
"\",\"selection_signature\":\"" + selectionSignature +
664677
"\",\"width\":" + parseInt(scheduleWidth) +
665678
",\"height\":" + parseInt(scheduleHeight) +
666679
",\"black_and_white\":" + getScheduleColourMode() +
680+
",\"year\":" + selectedYear +
667681
",\"week\":" + parseInt(week) +
668682
",\"day\":" + parseInt(weekDay) + "}"
669683
}).then(scheduleResp => {
@@ -746,6 +760,19 @@ function fetchRenderKeyFromAPI() {
746760
});
747761
}
748762

763+
function fetchSignatureFromAPI(to_sign) {
764+
return APIFetch(SCHEDULE_API_PREFIX + "signature", {
765+
method: "POST",
766+
headers: {
767+
"Content-Type": "application/json"
768+
},
769+
body: "\"" + to_sign + "\""
770+
})
771+
.then(response => {
772+
return response.json();
773+
});
774+
}
775+
749776
function rebuildClassGUIDCache() {
750777
return new Promise(resolve => {
751778
fetchClassGUIDsFromAPI()

0 commit comments

Comments
 (0)