/** * 全局运行时数据 */ export const GLOBAL_DATA = { filtedLeagues: [], filtedGames: [], gamesMap: {}, straightFixturesVersion: 0, straightFixturesCount: 0, specialFixturesVersion: 0, specialFixturesCount: 0, straightOddsVersion: 0, // straightOddsCount: 0, specialsOddsVersion: 0, // specialsOddsCount: 0, currencies: [], currenciesUpdatedAt: 0, requestErrorCount: 0, loopActive: false, loopResultTime: 0, }; export const getCurrenciesInfo = () => { const { currencies, currenciesUpdatedAt } = GLOBAL_DATA; if (!currenciesUpdatedAt) { return Promise.reject({ cause: 503, message: 'currencies data is not ready', data: { currenciesUpdatedAt }, }); } return Promise.resolve({ data: currencies, updatedAt: currenciesUpdatedAt }); } export const findCurrencyInfo = (currencyCode) => { const code = currencyCode?.toUpperCase(); const currencies = GLOBAL_DATA.currencies?.currencies ?? GLOBAL_DATA.currencies; if (!code || !Array.isArray(currencies)) { return null; } return currencies.find(currency => currency.code?.toUpperCase() === code) ?? null; } const normalizeIds = (ids) => { if (ids === undefined || ids === null || ids === '') { return []; } if (Array.isArray(ids)) { return ids.flatMap(normalizeIds); } return String(ids).split(',').map(id => id.trim()).filter(Boolean); } export const getEventsByIds = (ids) => { const normalizedIds = normalizeIds(ids); const { gamesMap={} } = GLOBAL_DATA; if (!normalizedIds.length) { return Object.values(gamesMap); } return normalizedIds.map(id => gamesMap[id]).filter(Boolean); }