Skip to content

Commit 933cb07

Browse files
hh
1 parent c464f4f commit 933cb07

3 files changed

Lines changed: 66 additions & 66 deletions

File tree

package-lock.json

Lines changed: 31 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pages/api/Sports/sportsData.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ const DEFAULT_HEADERS: HeaderMap = {
3030
'upgrade-insecure-requests': '1',
3131
'user-agent': DEFAULT_USER_AGENT,
3232
};
33-
const REQUEST_TIMEOUT_MS = 45000;
34-
const REQUEST_DELAY_MS = 1000;
35-
const RETRY_BASE_DELAY_MS = 1000;
33+
const REQUEST_TIMEOUT_MS = 450;
34+
const REQUEST_DELAY_MS = 100;
35+
const RETRY_BASE_DELAY_MS = 100;
3636
const MAX_RETRIES = 2;
3737
const RETRY_STATUS_CODES = new Set( [ 429, 503 ] );
3838
const ALLOWED_HEADER_KEYS = new Set( [
@@ -348,7 +348,7 @@ const normalizeHeaderValue = ( value: unknown ) => {
348348

349349
const pickForwardedHeaders = (
350350
value: unknown,
351-
options: { allowCookie?: boolean } = {}
351+
options: { allowCookie?: boolean; } = {}
352352
): HeaderMap => {
353353
const allowCookie = options.allowCookie ?? true;
354354

scripts/refresh-sports-cache.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,64 @@
1-
const fs = require('fs');
2-
const path = require('path');
1+
const fs = require( 'fs' );
2+
const path = require( 'path' );
33

44
const DEFAULT_BASE_URL = 'http://localhost:3000';
5-
const BASE_URL = (process.env.SPORTS_REFRESH_BASE_URL || DEFAULT_BASE_URL).replace(/\/$/, '');
6-
const SETS_PATH = path.join(__dirname, '..', 'constants', 'cardSets.ts');
5+
const BASE_URL = ( process.env.SPORTS_REFRESH_BASE_URL || DEFAULT_BASE_URL ).replace( /\/$/, '' );
6+
const SETS_PATH = path.join( __dirname, '..', 'constants', 'cardSets.ts' );
77

88
const readCardSets = () => {
9-
const source = fs.readFileSync(SETS_PATH, 'utf8');
10-
const matches = source.match(/['"]([^'"]+)['"]/g) || [];
9+
const source = fs.readFileSync( SETS_PATH, 'utf8' );
10+
const matches = source.match( /['"]([^'"]+)['"]/g ) || [];
1111
return matches
12-
.map((match) => match.replace(/^['"]|['"]$/g, '').trim())
13-
.filter(Boolean);
12+
.map( ( match ) => match.replace( /^['"]|['"]$/g, '' ).trim() )
13+
.filter( Boolean );
1414
};
1515

16-
const refreshCardSet = async (cardSet) => {
17-
const response = await fetch(`${BASE_URL}/api/Sports/sportsData`, {
16+
const refreshCardSet = async ( cardSet ) => {
17+
const response = await fetch( `${ BASE_URL }/api/Sports/sportsData`, {
1818
method: 'POST',
1919
headers: {
2020
'Content-Type': 'application/json',
2121
},
22-
body: JSON.stringify({ cardSet }),
23-
});
22+
body: JSON.stringify( { cardSet } ),
23+
} );
2424

25-
if (!response.ok) {
25+
if ( !response.ok ) {
2626
const text = await response.text();
27-
throw new Error(`Failed (${response.status}) ${text}`);
27+
throw new Error( `Failed (${ response.status }) ${ text }` );
2828
}
2929

3030
return response.json();
3131
};
3232

3333
const run = async () => {
34-
if (!fs.existsSync(SETS_PATH)) {
35-
console.error(`Card set list not found at ${SETS_PATH}`);
36-
process.exit(1);
34+
if ( !fs.existsSync( SETS_PATH ) ) {
35+
console.error( `Card set list not found at ${ SETS_PATH }` );
36+
process.exit( 1 );
3737
}
3838

3939
const sets = readCardSets();
40-
if (!sets.length) {
41-
console.error('No card sets found to refresh.');
42-
process.exit(1);
40+
if ( !sets.length ) {
41+
console.error( 'No card sets found to refresh.' );
42+
process.exit( 1 );
4343
}
4444

45-
console.log(`Refreshing ${sets.length} sets using ${BASE_URL}...`);
45+
console.log( `Refreshing ${ sets.length } sets using ${ BASE_URL }...` );
4646

4747
let successCount = 0;
48-
for (const cardSet of sets) {
48+
for ( const cardSet of sets ) {
4949
try {
50-
await refreshCardSet(cardSet);
50+
await refreshCardSet( cardSet );
5151
successCount += 1;
52-
console.log(`? ${cardSet}`);
53-
} catch (error) {
54-
console.error(`? ${cardSet}: ${error.message || error}`);
52+
console.log( `? ${ cardSet }` );
53+
} catch ( error ) {
54+
console.error( `? ${ cardSet }: ${ error.message || error }` );
5555
}
5656
}
5757

58-
console.log(`Done. ${successCount}/${sets.length} sets refreshed.`);
58+
console.log( `Done. ${ successCount }/${ sets.length } sets refreshed.` );
5959
};
6060

61-
run().catch((error) => {
62-
console.error(error);
63-
process.exit(1);
64-
});
61+
run().catch( ( error ) => {
62+
console.error( error );
63+
process.exit( 1 );
64+
} );

0 commit comments

Comments
 (0)