|
|
@@ -8,6 +8,7 @@ const fs = require('fs');
|
|
|
const path = require('path');
|
|
|
|
|
|
const GamesCacheFile = path.join(__dirname, '../data/games.cache');
|
|
|
+const DevGameTastFile = path.join(__dirname, '../data/gameTast.json');
|
|
|
|
|
|
const childOptions = process.env.NODE_ENV == 'development' ? {
|
|
|
execArgv: ['--inspect=9228'],
|
|
|
@@ -18,17 +19,18 @@ const events_child = fork('./triangle/eventsMatch.js', [], childOptions);
|
|
|
|
|
|
const PS_IOR_KEYS = [
|
|
|
['0', 'ior_mh', 'ior_mn', 'ior_mc'],
|
|
|
- // ['0', 'ior_rh_05', 'ior_mn', 'ior_rc_05'],
|
|
|
['-1', 'ior_rh_15', 'ior_wmh_1', 'ior_rac_05'],
|
|
|
['-2', 'ior_rh_25', 'ior_wmh_2', 'ior_rac_15'],
|
|
|
['+1', 'ior_rah_05', 'ior_wmc_1', 'ior_rc_15'],
|
|
|
['+2', 'ior_rah_15', 'ior_wmc_2', 'ior_rc_25'],
|
|
|
- // ['0-1', 'ior_ot_0', 'ior_os_0-1', 'ior_ot_1'],
|
|
|
+ ['0-1', 'ior_ot_0', 'ior_os_0-1', 'ior_ot_1'],
|
|
|
['2-3', 'ior_ot_2', 'ior_os_2-3', 'ior_ot_3'],
|
|
|
];
|
|
|
|
|
|
-const BASE_URL = 'https://api.qboss.vip/api/p';
|
|
|
+// 测试环境
|
|
|
+// const BASE_URL = 'https://dev.api.czxd8.com/api/p';
|
|
|
const IS_DEV = process.env.NODE_ENV == 'development';
|
|
|
+const BASE_URL = 'https://api.qboss.vip/api/p';
|
|
|
|
|
|
const GAMES = {
|
|
|
Leagues: {},
|
|
|
@@ -378,15 +380,29 @@ const getGamesEvents = ({ platform, relIds = [] } = {}) => {
|
|
|
/**
|
|
|
* 获取关联比赛
|
|
|
*/
|
|
|
+const getDevGameTast = () => {
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ const data = Cache.getData(DevGameTastFile, true);
|
|
|
+ resolve({data});
|
|
|
+ });
|
|
|
+}
|
|
|
const fetchGamesRelation = async (mk='') => {
|
|
|
- return axios.get(`${BASE_URL}/getGameTast?mk=${mk}`)
|
|
|
- .then(res => {
|
|
|
- if (res.data.code == 0) {
|
|
|
- const now = Date.now();
|
|
|
- const gamesRelation = res.data.data?.filter(item => {
|
|
|
+ const getGameTast = Promise.all([
|
|
|
+ getDevGameTast(),
|
|
|
+ axios.get(`${BASE_URL}/getGameTast?mk=${mk}`)
|
|
|
+ ]);
|
|
|
+ return getGameTast.then(([res1, res2]) => {
|
|
|
+ const resData = res1.data ?? res2.data;
|
|
|
+ if (resData.code == 0) {
|
|
|
+ const nowTime = Date.now();
|
|
|
+ const gamesRelation = resData.data?.filter(item => {
|
|
|
const timestamp = new Date(item.timestamp).getTime();
|
|
|
+ if (nowTime > timestamp) {
|
|
|
+ item.mk = 2;
|
|
|
+ }
|
|
|
item.timestamp = timestamp;
|
|
|
- return timestamp > now;
|
|
|
+ const expireTime = timestamp + 1000*60*60*2;
|
|
|
+ return expireTime > nowTime;
|
|
|
}).map(item => {
|
|
|
const {
|
|
|
id, mk, league_name,
|
|
|
@@ -428,11 +444,11 @@ const fetchGamesRelation = async (mk='') => {
|
|
|
timestamp
|
|
|
} : null
|
|
|
};
|
|
|
- return { id: ps_event_id, mk, rel };
|
|
|
+ return { id: ps_event_id, mk, rel, timestamp };
|
|
|
}) ?? [];
|
|
|
return gamesRelation;
|
|
|
}
|
|
|
- return Promise.reject(new Error(res.data.message));
|
|
|
+ return Promise.reject(new Error(resData.message));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -442,7 +458,8 @@ const getGamesRelation = ({ mk, listEvents } = {}) => {
|
|
|
return true;
|
|
|
}
|
|
|
return item.mk == mk;
|
|
|
- });
|
|
|
+ }).sort((a, b) => a.timestamp - b.timestamp);
|
|
|
+
|
|
|
if (listEvents) {
|
|
|
return relations;
|
|
|
}
|
|
|
@@ -463,8 +480,7 @@ const getGamesRelation = ({ mk, listEvents } = {}) => {
|
|
|
*/
|
|
|
const updateGamesRelation = () => {
|
|
|
fetchGamesRelation()
|
|
|
- .then(res => {
|
|
|
- const gamesRelation = res.flat();
|
|
|
+ .then(gamesRelation => {
|
|
|
|
|
|
const updateCount = {
|
|
|
add: 0,
|
|
|
@@ -493,9 +509,9 @@ const updateGamesRelation = () => {
|
|
|
updateCount.delete ++;
|
|
|
}
|
|
|
else {
|
|
|
- const { rel } = GAMES.Relations[id];
|
|
|
- const relTime = rel.ps?.timestamp;
|
|
|
- if (relTime && relTime < Date.now()) {
|
|
|
+ const { timestamp } = GAMES.Relations[id];
|
|
|
+ const expireTime = timestamp ? timestamp + 1000*60*60*2 : 0;
|
|
|
+ if (expireTime && expireTime < Date.now()) {
|
|
|
delete GAMES.Relations[id];
|
|
|
updateCount.delete ++;
|
|
|
}
|