@@ -25,9 +25,9 @@ async function getCurrentKHLTeams(): Promise<TeamInfo> {
25
25
return teams ;
26
26
}
27
27
28
- async function getFiveVFiveSeasons ( ) : Promise < Array < { name : string ; id : number } > > {
28
+ async function getFiveVFiveSeasons ( version : string ) : Promise < Array < { name : string ; id : number } > > {
29
29
const ans = (
30
- ( await get ( `https://snokinghockeyleague.com/api/season/all/0?v=1021270 ` ) ) as {
30
+ ( await get ( `https://snokinghockeyleague.com/api/season/all/0?v=${ version } ` ) ) as {
31
31
seasons : [
32
32
{
33
33
name : string ;
@@ -56,9 +56,17 @@ async function getFiveVFiveSeasons(): Promise<Array<{ name: string; id: number }
56
56
return ans ;
57
57
}
58
58
59
- async function getFiveVFiveCurrentTeams ( { name, id } : { name : string ; id : number } ) : Promise < TeamInfo > {
59
+ async function getFiveVFiveCurrentTeams ( {
60
+ name,
61
+ id,
62
+ version,
63
+ } : {
64
+ name : string ;
65
+ id : number ;
66
+ version : string ;
67
+ } ) : Promise < TeamInfo > {
60
68
return (
61
- ( await get ( `https://snokinghockeyleague.com/api/team/list/${ id } /0?v=1021270 ` ) ) as [
69
+ ( await get ( `https://snokinghockeyleague.com/api/team/list/${ id } /0?v=${ version } ` ) ) as [
62
70
{
63
71
name : string ;
64
72
divisionName : string ;
@@ -74,9 +82,9 @@ async function getFiveVFiveCurrentTeams({ name, id }: { name: string; id: number
74
82
} ) ) ;
75
83
}
76
84
77
- async function getPondSeasons ( ) : Promise < Array < { name : string ; id : number } > > {
85
+ async function getPondSeasons ( version : string ) : Promise < Array < { name : string ; id : number } > > {
78
86
return (
79
- ( await get ( `https://snokingpondhockey.com/api/season/all/0?v=1021270 ` ) ) as {
87
+ ( await get ( `https://snokingpondhockey.com/api/season/all/0?v=${ version } ` ) ) as {
80
88
seasons : [ { name : string ; id : number } ] ;
81
89
}
82
90
) . seasons . map ( ( x : { name : string ; id : number } ) => ( {
@@ -85,13 +93,13 @@ async function getPondSeasons(): Promise<Array<{ name: string; id: number }>> {
85
93
} ) ) ;
86
94
}
87
95
88
- async function getPondSeasonCurrentTeams ( ) : Promise <
89
- Array < { name : string ; snokingUrl : string ; teamId : string ; isSnoking : boolean } >
90
- > {
91
- const { id, name : seasonName } = ( await getPondSeasons ( ) ) [ 0 ] ;
96
+ async function getPondSeasonCurrentTeams (
97
+ version : string
98
+ ) : Promise < Array < { name : string ; snokingUrl : string ; teamId : string ; isSnoking : boolean } > > {
99
+ const { id, name : seasonName } = ( await getPondSeasons ( version ) ) [ 0 ] ;
92
100
93
101
return (
94
- ( await get ( `https://snokingpondhockey.com/api/team/list/${ id } /0?v=1021270 ` ) ) as [
102
+ ( await get ( `https://snokingpondhockey.com/api/team/list/${ id } /0?v=${ version } ` ) ) as [
95
103
{ name : string ; divisionName : string ; teamId : string ; seasonId : string }
96
104
]
97
105
) . map ( ( x ) => {
@@ -108,6 +116,16 @@ export async function getCurrentTeams(): Promise<{
108
116
teams : TeamInfo ;
109
117
errors : ReactElement [ ] ;
110
118
} > {
119
+ const main = ( await get ( "https://snokinghockeyleague.com/" ) ) as string ;
120
+ const match = main . match ( / m e t a n a m e = \" v e r s i o n \" \s + c o n t e n t = \" ( \d + ) \" / ) ;
121
+ if ( ! match || match . length < 2 ) {
122
+ return {
123
+ teams : [ ] ,
124
+ errors : [ < > Data is not currently available. Please try again later if you require data for that league.</ > ] ,
125
+ } ;
126
+ }
127
+
128
+ const version = match [ 1 ] ;
111
129
const safelyGetTeams = async ( getter : ( ) => Promise < TeamInfo > , errorMessage : ReactElement ) => {
112
130
try {
113
131
const data = await getter ( ) ;
@@ -128,12 +146,12 @@ export async function getCurrentTeams(): Promise<{
128
146
// we now just show every team that is in a season for this calendar year. This means that we'll at some point have 3 seasons showing
129
147
// for the main SKAHL league, but that's less interruptive then new seasons breaking our heuristic.
130
148
const currentYear = new Date ( ) . getFullYear ( ) . toString ( ) ;
131
- const allSKAHLTeamsSeasons = await getFiveVFiveSeasons ( ) ;
149
+ const allSKAHLTeamsSeasons = await getFiveVFiveSeasons ( version ) ;
132
150
const allCurrentSKAHLSeasons = allSKAHLTeamsSeasons . filter ( ( season ) => season . name . indexOf ( currentYear ) >= 0 ) ;
133
151
134
152
const dataForNonSKAHLSite = [
135
153
safelyGetTeams (
136
- ( ) => getPondSeasonCurrentTeams ( ) ,
154
+ ( ) => getPondSeasonCurrentTeams ( version ) ,
137
155
< >
138
156
< b > SKAHL Pond</ b > data is not currently available. Please try again later if you require data for that
139
157
league.
@@ -151,7 +169,7 @@ export async function getCurrentTeams(): Promise<{
151
169
152
170
const dataForSKAHLSite = allCurrentSKAHLSeasons . map ( ( season ) =>
153
171
safelyGetTeams (
154
- ( ) => getFiveVFiveCurrentTeams ( season ) ,
172
+ ( ) => getFiveVFiveCurrentTeams ( { ... season , version } ) ,
155
173
< >
156
174
< b > { season . name } </ b > data is not currently available. Please try again later if you require data for
157
175
that league.
0 commit comments