|
|
@@ -20,8 +20,9 @@ const gamesMapCacheFile = path.join(__dirname, './cache/pinnacleGamesCache.json'
|
|
|
const globalDataCacheFile = path.join(__dirname, './cache/pinnacleGlobalDataCache.json');
|
|
|
|
|
|
const GLOBAL_DATA = {
|
|
|
- filteredLeagues: [],
|
|
|
- filteredGames: [],
|
|
|
+ relatedLeagues: [],
|
|
|
+ selectedLeagues: [],
|
|
|
+ relatedGames: [],
|
|
|
gamesMap: {},
|
|
|
straightFixturesVersion: 0,
|
|
|
straightFixturesCount: 0,
|
|
|
@@ -65,12 +66,12 @@ const updateWebLeagues = async () => {
|
|
|
return Array.from(leaguesMap.values()).sort((a, b) => a.id - b.id);
|
|
|
})
|
|
|
.then(leagues => {
|
|
|
- Logs.outDev('update leagues list', leagues);
|
|
|
+ Logs.outDev('update leagues list', leagues.length);
|
|
|
return platformPost('/api/platforms/update_leagues', { platform: 'pinnacle', leagues });
|
|
|
})
|
|
|
.then(() => {
|
|
|
Logs.outDev('leagues list updated');
|
|
|
- return Promise.resolve(60);
|
|
|
+ return Promise.resolve({ delay: 60 });
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -79,7 +80,8 @@ const updateWebLeagues = async () => {
|
|
|
*/
|
|
|
const updateWebLeaguesLoop = () => {
|
|
|
updateWebLeagues()
|
|
|
- .then(delay => {
|
|
|
+ .then(data => {
|
|
|
+ const { delay=5 } = data ?? {};
|
|
|
setTimeout(() => {
|
|
|
updateWebLeaguesLoop();
|
|
|
}, 1000 * delay);
|
|
|
@@ -96,23 +98,23 @@ const updateWebLeaguesLoop = () => {
|
|
|
* 更新Web比赛列表
|
|
|
*/
|
|
|
const updateWebGames = async () => {
|
|
|
- if (!GLOBAL_DATA.filteredLeagues.length) {
|
|
|
- return Promise.resolve(5);
|
|
|
+ if (!GLOBAL_DATA.relatedLeagues.length) {
|
|
|
+ return Promise.resolve({ delay: 5 });
|
|
|
}
|
|
|
- const getWebGamesToday = pinnacleWebGames(GLOBAL_DATA.filteredLeagues, 1);
|
|
|
- const getWebGamesTomorrow = pinnacleWebGames(GLOBAL_DATA.filteredLeagues, 0);
|
|
|
+ const getWebGamesToday = pinnacleWebGames(GLOBAL_DATA.relatedLeagues, 1);
|
|
|
+ const getWebGamesTomorrow = pinnacleWebGames(GLOBAL_DATA.relatedLeagues, 0);
|
|
|
return Promise.all([getWebGamesToday, getWebGamesTomorrow])
|
|
|
.then(data => {
|
|
|
const [webGamesToday, webGamesTomorrow] = data;
|
|
|
return webGamesToday.concat(webGamesTomorrow).sort((a, b) => a.timestamp - b.timestamp);
|
|
|
})
|
|
|
.then(games => {
|
|
|
- Logs.outDev('update games list', games);
|
|
|
+ Logs.outDev('update games list', games.length);
|
|
|
return platformPost('/api/platforms/update_games', { platform: 'pinnacle', games });
|
|
|
})
|
|
|
.then(() => {
|
|
|
Logs.outDev('games list updated');
|
|
|
- return Promise.resolve(60);
|
|
|
+ return Promise.resolve({ delay: 60 });
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -121,7 +123,8 @@ const updateWebGames = async () => {
|
|
|
*/
|
|
|
const updateWebGamesLoop = () => {
|
|
|
updateWebGames()
|
|
|
- .then(delay => {
|
|
|
+ .then(data => {
|
|
|
+ const { delay=5 } = data ?? {};
|
|
|
setTimeout(() => {
|
|
|
updateWebGamesLoop();
|
|
|
}, 1000 * delay);
|
|
|
@@ -138,18 +141,18 @@ const updateWebGamesLoop = () => {
|
|
|
* 获取过滤后的联赛数据
|
|
|
* @returns
|
|
|
*/
|
|
|
-const updateFilteredLeagues = () => {
|
|
|
- platformGet('/api/platforms/get_filtered_leagues', { platform: 'pinnacle' })
|
|
|
+const updateRelatedLeagues = () => {
|
|
|
+ platformGet('/api/platforms/get_related_leagues', { platform: 'pinnacle' })
|
|
|
.then(res => {
|
|
|
- const { data: filteredLeagues } = res;
|
|
|
- GLOBAL_DATA.filteredLeagues = filteredLeagues.map(item => item.id);
|
|
|
+ const { data: relatedLeagues } = res;
|
|
|
+ GLOBAL_DATA.relatedLeagues = relatedLeagues.map(item => item.id);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
Logs.err('failed to update filtered leagues', error.message);
|
|
|
})
|
|
|
.finally(() => {
|
|
|
setTimeout(() => {
|
|
|
- updateFilteredLeagues();
|
|
|
+ updateRelatedLeagues();
|
|
|
}, 1000 * 10);
|
|
|
});
|
|
|
}
|
|
|
@@ -158,18 +161,19 @@ const updateFilteredLeagues = () => {
|
|
|
* 获取过滤后的比赛数据
|
|
|
* @returns
|
|
|
*/
|
|
|
-const updateFilteredGames = () => {
|
|
|
- platformGet('/api/platforms/get_filtered_games', { platform: 'pinnacle' })
|
|
|
+const updateRelatedGames = () => {
|
|
|
+ platformGet('/api/platforms/get_related_games', { platform: 'pinnacle' })
|
|
|
.then(res => {
|
|
|
- const { data: filteredGames } = res;
|
|
|
- GLOBAL_DATA.filteredGames = filteredGames.map(item => item.id);
|
|
|
+ const { data: relatedGames } = res;
|
|
|
+ GLOBAL_DATA.relatedGames = relatedGames.map(item => item.id);
|
|
|
+ GLOBAL_DATA.selectedLeagues = [...new Set(relatedGames.map(item => item.leagueId))];
|
|
|
})
|
|
|
.catch(error => {
|
|
|
- Logs.err('failed to update filtered games', error.message);
|
|
|
+ Logs.err('failed to update related games', error.message);
|
|
|
})
|
|
|
.finally(() => {
|
|
|
setTimeout(() => {
|
|
|
- updateFilteredGames();
|
|
|
+ updateRelatedGames();
|
|
|
}, 1000 * 10);
|
|
|
});
|
|
|
}
|
|
|
@@ -179,11 +183,13 @@ const updateFilteredGames = () => {
|
|
|
* @returns
|
|
|
*/
|
|
|
const getStraightFixtures = async () => {
|
|
|
- if (!GLOBAL_DATA.filteredLeagues.length) {
|
|
|
- resetVersionsCount();
|
|
|
- return Promise.reject(new Error('no filtered leagues', { cause: 400 }));
|
|
|
+ if (!GLOBAL_DATA.selectedLeagues.length) {
|
|
|
+ // resetVersionsCount();
|
|
|
+ GLOBAL_DATA.straightFixturesVersion = 0;
|
|
|
+ return Promise.resolve({ games: [], update: 'full' });
|
|
|
+ // return Promise.reject(new Error('no related leagues', { cause: 400 }));
|
|
|
}
|
|
|
- const leagueIds = GLOBAL_DATA.filteredLeagues.join(',');
|
|
|
+ const leagueIds = GLOBAL_DATA.selectedLeagues.join(',');
|
|
|
let since = GLOBAL_DATA.straightFixturesVersion;
|
|
|
if (GLOBAL_DATA.straightFixturesCount >= 12) {
|
|
|
since = 0;
|
|
|
@@ -250,11 +256,13 @@ const updateStraightFixtures = async () => {
|
|
|
* @returns
|
|
|
*/
|
|
|
const getStraightOdds = async () => {
|
|
|
- if (!GLOBAL_DATA.filteredLeagues.length) {
|
|
|
- resetVersionsCount();
|
|
|
- return Promise.reject(new Error('no filtered leagues', { cause: 400 }));
|
|
|
+ if (!GLOBAL_DATA.selectedLeagues.length) {
|
|
|
+ // resetVersionsCount();
|
|
|
+ GLOBAL_DATA.straightOddsVersion = 0;
|
|
|
+ return Promise.resolve([]);
|
|
|
+ // return Promise.reject(new Error('no related leagues', { cause: 400 }));
|
|
|
}
|
|
|
- const leagueIds = GLOBAL_DATA.filteredLeagues.join(',');
|
|
|
+ const leagueIds = GLOBAL_DATA.selectedLeagues.join(',');
|
|
|
const since = GLOBAL_DATA.straightOddsVersion;
|
|
|
// if (GLOBAL_DATA.straightOddsCount >= 27) {
|
|
|
// since = 0;
|
|
|
@@ -312,11 +320,13 @@ const updateStraightOdds = async () => {
|
|
|
* @returns
|
|
|
*/
|
|
|
const getSpecialFixtures = async () => {
|
|
|
- if (!GLOBAL_DATA.filteredLeagues.length) {
|
|
|
- resetVersionsCount();
|
|
|
- return Promise.reject(new Error('no filtered leagues', { cause: 400 }));
|
|
|
+ if (!GLOBAL_DATA.selectedLeagues.length) {
|
|
|
+ // resetVersionsCount();
|
|
|
+ GLOBAL_DATA.specialFixturesVersion = 0;
|
|
|
+ return Promise.resolve({ specials: [], update: 'full' });
|
|
|
+ // return Promise.reject(new Error('no related leagues', { cause: 400 }));
|
|
|
}
|
|
|
- const leagueIds = GLOBAL_DATA.filteredLeagues.join(',');
|
|
|
+ const leagueIds = GLOBAL_DATA.selectedLeagues.join(',');
|
|
|
let since = GLOBAL_DATA.specialFixturesVersion;
|
|
|
if (GLOBAL_DATA.specialFixturesCount >= 18) {
|
|
|
since = 0;
|
|
|
@@ -446,11 +456,13 @@ const updateSpecialFixtures = async () => {
|
|
|
* @returns
|
|
|
*/
|
|
|
const getSpecialsOdds = async () => {
|
|
|
- if (!GLOBAL_DATA.filteredLeagues.length) {
|
|
|
- resetVersionsCount();
|
|
|
- return Promise.reject(new Error('no filtered leagues', { cause: 400 }));
|
|
|
+ if (!GLOBAL_DATA.selectedLeagues.length) {
|
|
|
+ // resetVersionsCount();
|
|
|
+ GLOBAL_DATA.specialsOddsVersion = 0;
|
|
|
+ return Promise.resolve([]);
|
|
|
+ // return Promise.reject(new Error('no related leagues', { cause: 400 }));
|
|
|
}
|
|
|
- const leagueIds = GLOBAL_DATA.filteredLeagues.join(',');
|
|
|
+ const leagueIds = GLOBAL_DATA.selectedLeagues.join(',');
|
|
|
const since = GLOBAL_DATA.specialsOddsVersion;
|
|
|
// if (GLOBAL_DATA.specialsOddsCount >= 33) {
|
|
|
// since = 0;
|
|
|
@@ -517,12 +529,12 @@ const getInRunning = async () => {
|
|
|
const sportId = 29;
|
|
|
const leagues = data.sports?.find(sport => sport.id == sportId)?.leagues ?? [];
|
|
|
return leagues.filter(league => {
|
|
|
- if (!GLOBAL_DATA.filteredLeagues.length) {
|
|
|
+ if (!GLOBAL_DATA.selectedLeagues.length) {
|
|
|
return true;
|
|
|
}
|
|
|
const { id } = league;
|
|
|
- const filteredLeaguesSet = new Set(GLOBAL_DATA.filteredLeagues);
|
|
|
- return filteredLeaguesSet.has(id);
|
|
|
+ const selectedLeaguesSet = new Set(GLOBAL_DATA.selectedLeagues);
|
|
|
+ return selectedLeaguesSet.has(id);
|
|
|
}).flatMap(league => league.events);
|
|
|
});
|
|
|
}
|
|
|
@@ -554,14 +566,8 @@ const updateInRunning = async () => {
|
|
|
* @returns {Object}
|
|
|
*/
|
|
|
const getGamesEvents = () => {
|
|
|
- const {
|
|
|
- filteredGames, gamesMap,
|
|
|
- straightFixturesVersion: sfv,
|
|
|
- specialFixturesVersion: pfv,
|
|
|
- straightOddsVersion: sov,
|
|
|
- specialsOddsVersion: pov
|
|
|
- } = GLOBAL_DATA;
|
|
|
- const filteredGamesSet = new Set(filteredGames);
|
|
|
+ const { relatedGames, gamesMap } = GLOBAL_DATA;
|
|
|
+ const relatedGamesSet = new Set(relatedGames);
|
|
|
const nowTime = Date.now();
|
|
|
const gamesData = {};
|
|
|
Object.values(gamesMap).forEach(game => {
|
|
|
@@ -592,12 +598,12 @@ const getGamesEvents = () => {
|
|
|
}
|
|
|
|
|
|
let actived = false;
|
|
|
- if (liveStatus != 1 && (filteredGamesSet.has(id) || !filteredGames.length)) {
|
|
|
+ if (liveStatus != 1 && (relatedGamesSet.has(id) || !relatedGames.length)) {
|
|
|
actived = true; // 在赛前列表中
|
|
|
game.id = id;
|
|
|
game.originId = 0;
|
|
|
}
|
|
|
- else if (liveStatus == 1 && (filteredGamesSet.has(parentId) || !filteredGames.length)) {
|
|
|
+ else if (liveStatus == 1 && (relatedGamesSet.has(parentId) || !relatedGames.length)) {
|
|
|
actived = true; // 在滚球列表中
|
|
|
game.id = parentId;
|
|
|
game.originId = id;
|
|
|
@@ -612,7 +618,7 @@ const getGamesEvents = () => {
|
|
|
}
|
|
|
});
|
|
|
const games = Object.values(gamesData).flat();
|
|
|
- const timestamp = Math.max(sfv, pfv, sov, pov);
|
|
|
+ const timestamp = nowTime;
|
|
|
const data = { games, timestamp };
|
|
|
return data;
|
|
|
}
|
|
|
@@ -676,10 +682,13 @@ const pinnacleDataLoop = () => {
|
|
|
}
|
|
|
})
|
|
|
.finally(() => {
|
|
|
- const { loopActive } = GLOBAL_DATA;
|
|
|
- let loopDelay = 1000 * 5;
|
|
|
+ const { loopActive, selectedLeagues } = GLOBAL_DATA;
|
|
|
+ let loopDelay = 5_000;
|
|
|
if (!loopActive) {
|
|
|
- loopDelay = 1000 * 60;
|
|
|
+ loopDelay = 60_000;
|
|
|
+ resetVersionsCount();
|
|
|
+ }
|
|
|
+ else if (!selectedLeagues.length) {
|
|
|
resetVersionsCount();
|
|
|
}
|
|
|
else {
|
|
|
@@ -716,8 +725,8 @@ const main = () => {
|
|
|
Logs.err('USERNAME or PASSWORD is not set');
|
|
|
return;
|
|
|
}
|
|
|
- updateFilteredLeagues();
|
|
|
- updateFilteredGames();
|
|
|
+ updateRelatedLeagues();
|
|
|
+ updateRelatedGames();
|
|
|
loadGlobalDataFromCache()
|
|
|
.then(() => {
|
|
|
Logs.out('global data loaded');
|