@@ -637,21 +637,34 @@ function intoText(obj) {
637
637
638
638
function getScheduleJSON ( className , week , weekDay ) {
639
639
return new Promise ( async ( resolve , reject ) => {
640
- let renderKeyResp , classGUID ;
640
+ let renderKeyResp ;
641
+ let selectionSignatureResp ;
641
642
642
643
try {
643
644
const resp = await Promise . all ( [
644
645
fetchRenderKeyFromAPI ( ) ,
645
- getClassGUIDByName ( className )
646
+ fetchSignatureFromAPI ( className )
646
647
] ) ;
647
648
648
649
renderKeyResp = resp [ 0 ] ;
649
- classGUID = resp [ 1 ] ;
650
+ selectionSignatureResp = resp [ 1 ] ;
650
651
} catch ( error ) {
651
652
return reject ( error ) ;
652
653
}
653
654
654
655
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.
655
668
656
669
APIFetch ( SCHEDULE_API_PREFIX + "schedule" , {
657
670
method : "POST" ,
@@ -660,10 +673,11 @@ function getScheduleJSON(className, week, weekDay) {
660
673
} ,
661
674
body : "{\"render_key\":\"" + renderKey +
662
675
"\",\"unit_guid\":\"" + BERZAN_UNIT_GUID +
663
- "\",\"selection_signature\":\"" + classGUID +
676
+ "\",\"selection_signature\":\"" + selectionSignature +
664
677
"\",\"width\":" + parseInt ( scheduleWidth ) +
665
678
",\"height\":" + parseInt ( scheduleHeight ) +
666
679
",\"black_and_white\":" + getScheduleColourMode ( ) +
680
+ ",\"year\":" + selectedYear +
667
681
",\"week\":" + parseInt ( week ) +
668
682
",\"day\":" + parseInt ( weekDay ) + "}"
669
683
} ) . then ( scheduleResp => {
@@ -746,6 +760,19 @@ function fetchRenderKeyFromAPI() {
746
760
} ) ;
747
761
}
748
762
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
+
749
776
function rebuildClassGUIDCache ( ) {
750
777
return new Promise ( resolve => {
751
778
fetchClassGUIDsFromAPI ( )
0 commit comments