11import Database from '../database.js' ;
2- import crypto from 'crypto' ;
32import { URL } from 'url' ;
43import { tagType , attractionType , entityType } from '../parkTypes.js' ;
5- import { Blowfish } from 'egoroof-blowfish' ;
64
75const poiEntityTypes = [
86 'attraction' ,
@@ -33,30 +31,22 @@ export class DatabaseEuropaPark extends Database {
3331 * @param {object } options
3432 */
3533 constructor ( options = { } ) {
36- options . fbAppId = '' ;
37- options . fbApiKey = '' ;
38- options . fbProjectId = '' ;
3934 options . apiBase = '' ;
40- options . encKey = '' ;
41- options . encIV = '' ;
4235 options . authURL = '' ;
43- options . userKey = options . userKey || 'v3_live_android_exozet_api_username ';
44- options . passKey = options . passKey || 'v3_live_android_exozet_api_password ';
45- options . appVersion = options . appVersion || '10.1 .0' ;
36+ options . clientId = ' ';
37+ options . clientSecret = ' ';
38+ options . appVersion = options . appVersion || '16.0 .0' ;
4639
4740 options . configPrefixes = [ 'EUROPAPARK' ] . concat ( options . configPrefixes || [ ] ) ;
4841
4942 super ( options ) ;
5043
51- if ( ! this . config . fbApiKey ) throw new Error ( 'Missing Europa Park Firebase API Key' ) ;
52- if ( ! this . config . fbAppId ) throw new Error ( 'Missing Europa Park Firebase App ID' ) ;
53- if ( ! this . config . fbProjectId ) throw new Error ( 'Missing Europa Park Firebase Project ID' ) ;
5444 if ( ! this . config . apiBase ) throw new Error ( 'Missing Europa Park API Base' ) ;
55- if ( ! this . config . encKey ) throw new Error ( 'Missing Europa Park Encryption Key' ) ;
56- if ( ! this . config . encIV ) throw new Error ( 'Missing Europa Park Encryption IV' ) ;
5745 if ( ! this . config . authURL ) throw new Error ( 'Missing Europa Park Token URL' ) ;
46+ if ( ! this . config . clientId ) throw new Error ( 'Missing Europa Park Client ID' ) ;
47+ if ( ! this . config . clientSecret ) throw new Error ( 'Missing Europa Park Client Secret' ) ;
5848
59- this . cache . version = 2 ;
49+ this . cache . version = 3 ;
6050
6151 this . http . injectForDomain ( {
6252 hostname : new URL ( this . config . authURL ) . hostname ,
@@ -69,17 +59,17 @@ export class DatabaseEuropaPark extends Database {
6959 } , async ( method , url , data , options ) => {
7060 options . headers [ 'user-agent' ] = `EuropaParkApp/${ this . config . appVersion } (Android)` ;
7161
72- const jwtToken = await this . getToken ( ) ;
73- if ( jwtToken === undefined ) {
74- // refetch Firebase settings and try again
75- await this . cache . set ( 'auth ' , undefined , - 1 ) ;
76- const jwtTokenRetry = await this . getToken ( ) ;
77- options . headers [ 'jwtauthorization ' ] = `Bearer ${ jwtTokenRetry } ` ;
62+ const token = await this . getToken ( ) ;
63+ if ( token === undefined ) {
64+ // retry token fetch
65+ await this . cache . set ( 'access_token ' , undefined , - 1 ) ;
66+ const tokenRetry = await this . getToken ( ) ;
67+ options . headers [ 'authorization ' ] = `Bearer ${ tokenRetry } ` ;
7868 } else {
79- options . headers [ 'jwtauthorization' ] = `Bearer ${ jwtToken } ` ;
80-
81- options . headers [ 'Accept-Language' ] = 'en' ;
69+ options . headers [ 'authorization' ] = `Bearer ${ token } ` ;
8270 }
71+
72+ options . headers [ 'accept-language' ] = 'en' ;
8373 } ) ;
8474
8575 this . http . injectForDomainResponse ( {
@@ -95,65 +85,6 @@ export class DatabaseEuropaPark extends Database {
9585
9686 return response ;
9787 } ) ;
98-
99- this . bf = new Blowfish ( this . config . encKey , Blowfish . MODE . CBC , Blowfish . PADDING . PKCS5 ) ;
100- this . bf . setIv ( this . config . encIV ) ;
101- }
102-
103- /**
104- * Get or generate a Firebase device ID
105- */
106- async getFirebaseID ( ) {
107- return await this . cache . wrap ( 'fid' , async ( ) => {
108- try {
109- const fidByteArray = crypto . randomBytes ( 17 ) . toJSON ( ) . data ;
110- fidByteArray [ 0 ] = 0b01110000 + ( fidByteArray [ 0 ] % 0b00010000 ) ;
111- const b64String = Buffer . from ( String . fromCharCode ( ...fidByteArray ) )
112- . toString ( 'base64' )
113- . replace ( / \+ / g, '-' )
114- . replace ( / \/ / g, '_' ) ;
115- const fid = b64String . substr ( 0 , 22 ) ;
116- return / ^ [ c d e f ] [ \w - ] { 21 } $ / . test ( fid ) ? fid : '' ;
117- } catch ( e ) {
118- this . emit ( 'error' , e ) ;
119- console . log ( e ) ;
120- return '' ;
121- }
122- } , 1000 * 60 * 60 * 24 * 8 ) ; // 8days
123- }
124-
125- /**
126- * Get Europa Park config keys
127- */
128- async getConfig ( ) {
129- return await this . cache . wrap ( 'auth' , async ( ) => {
130- const fid = await this . getFirebaseID ( ) ;
131-
132- const resp = await this . http (
133- 'POST' ,
134- `https://firebaseremoteconfig.googleapis.com/v1/projects/${ this . config . fbProjectId } /namespaces/firebase:fetch` ,
135- {
136- 'appInstanceId' : fid ,
137- 'appId' : this . config . fbAppId ,
138- 'packageName' : 'com.EuropaParkMackKG.EPGuide' ,
139- 'languageCode' : 'en_GB' ,
140- } , {
141- headers : {
142- 'X-Goog-Api-Key' : this . config . fbApiKey ,
143- } ,
144- } ,
145- ) ;
146-
147- const decrypt = ( str ) => {
148- return this . bf . decode ( Buffer . from ( str , 'base64' ) , Blowfish . TYPE . STRING ) ;
149- } ;
150-
151- const ret = { } ;
152- Object . keys ( resp . body . entries ) . forEach ( ( key ) => {
153- ret [ key ] = decrypt ( resp . body . entries [ key ] ) ;
154- } ) ;
155- return ret ;
156- } , 1000 * 60 * 60 * 6 ) ; // 6 hours
15788 }
15889
15990 /**
@@ -162,13 +93,12 @@ export class DatabaseEuropaPark extends Database {
16293 async getToken ( ) {
16394 let expiresIn = 1000 * 60 * 60 * 24 ; // default: 1 day
16495 return await this . cache . wrap ( 'access_token' , async ( ) => {
165- const config = await this . getConfig ( ) ;
16696 const resp = await this . http (
16797 'POST' ,
16898 this . config . authURL ,
16999 {
170- client_id : config [ this . config . userKey ] ,
171- client_secret : config [ this . config . passKey ] ,
100+ client_id : this . config . clientId ,
101+ client_secret : this . config . clientSecret ,
172102 grant_type : 'client_credentials' ,
173103 } ,
174104 {
@@ -200,9 +130,7 @@ export class DatabaseEuropaPark extends Database {
200130
201131 // if we haven't fetched in 12 hours or ever, fetch new data
202132 if ( ! existingData || ! lastUpdated || ( Date . now ( ) - lastUpdated ) > 1000 * 60 * 60 * 12 ) {
203- const newPOIData = ( await this . http ( 'GET' , `${ this . config . apiBase } /api/v2/poi-group` , {
204- status : [ 'live' ] ,
205- } , undefined , {
133+ const newPOIData = ( await this . http ( 'GET' , `${ this . config . apiBase } /api/v2/poi-group?status%5B%5D=live` , null , {
206134 open_timeout : 60 * 1000 , // 1 minute timeout for this request
207135 response_timeout : 60 * 1000 , // 1 minute timeout for this request
208136 read_timeout : 2 * 60 * 1000 , // 2 minute timeout for reading this request
@@ -244,9 +172,7 @@ export class DatabaseEuropaPark extends Database {
244172 */
245173 async getCalendar ( ) {
246174 return this . cache . wrap ( 'seasons' , async ( ) => {
247- return ( await this . http ( 'GET' , `${ this . config . apiBase } /api/v2/seasons` , {
248- status : [ 'live' ] ,
249- } ) ) . body ;
175+ return ( await this . http ( 'GET' , `${ this . config . apiBase } /api/v2/seasons?status%5B%5D=live` ) ) . body ;
250176 } , 1000 * 60 * 60 * 6 ) ;
251177 }
252178
@@ -265,9 +191,7 @@ export class DatabaseEuropaPark extends Database {
265191 async getShowTimes ( ) {
266192 return this . cache . wrap ( 'showtimes' , async ( ) => {
267193 // TODO - other languages? does this only include English performances?
268- return ( await this . http ( 'GET' , `${ this . config . apiBase } /api/v2/show-times` , {
269- status : 'live' ,
270- } ) ) . body ;
194+ return ( await this . http ( 'GET' , `${ this . config . apiBase } /api/v2/show-times?status%5B%5D=live` ) ) . body ;
271195 } , 1000 * 60 * 60 * 6 ) ;
272196 }
273197
0 commit comments