chore: bump version to 1.3.3
This commit is contained in:
@@ -36,9 +36,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.scrapeCooldown = void 0;
|
||||
exports.scrapeCooldown = exports.SteamAuthError = void 0;
|
||||
const axios_1 = __importDefault(require("axios"));
|
||||
const cheerio = __importStar(require("cheerio"));
|
||||
// Custom error to identify session death
|
||||
class SteamAuthError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "SteamAuthError";
|
||||
}
|
||||
}
|
||||
exports.SteamAuthError = SteamAuthError;
|
||||
const scrapeCooldown = async (steamId, steamLoginSecure) => {
|
||||
const url = `https://steamcommunity.com/profiles/${steamId}/gcpd/730?tab=matchmaking`;
|
||||
try {
|
||||
@@ -47,13 +55,17 @@ const scrapeCooldown = async (steamId, steamLoginSecure) => {
|
||||
'Cookie': steamLoginSecure,
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
||||
},
|
||||
timeout: 10000
|
||||
timeout: 10000,
|
||||
validateStatus: (status) => status < 500 // Allow redirects to handle them manually
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
if (response.data.includes('Sign In') || !response.data.includes('Personal Game Data')) {
|
||||
throw new Error('Invalid or expired steamLoginSecure cookie');
|
||||
// If Steam redirects us to the login page, the cookie is dead
|
||||
if (response.data.includes('Sign In') || response.request.path.includes('/login')) {
|
||||
throw new SteamAuthError('Invalid or expired steamLoginSecure cookie');
|
||||
}
|
||||
const $ = cheerio.load(response.data);
|
||||
if (!response.data.includes('Personal Game Data')) {
|
||||
throw new SteamAuthError('Session invalid: Personal Game Data not accessible');
|
||||
}
|
||||
// 1. Locate the specific table containing cooldown info
|
||||
let expirationDate = undefined;
|
||||
$('table').each((_, table) => {
|
||||
const headers = $(table).find('th').map((_, th) => $(th).text().trim()).get();
|
||||
@@ -63,25 +75,18 @@ const scrapeCooldown = async (steamId, steamLoginSecure) => {
|
||||
rows.each((_, row) => {
|
||||
const dateText = $(row).find('td').eq(expirationIndex).text().trim();
|
||||
if (dateText && dateText !== '') {
|
||||
// Steam uses 'GMT' which some JS engines don't parse well, replace with 'UTC'
|
||||
const cleanDateText = dateText.replace(' GMT', ' UTC');
|
||||
const parsed = new Date(cleanDateText);
|
||||
if (!isNaN(parsed.getTime())) {
|
||||
// We want the newest expiration date found
|
||||
if (!expirationDate || parsed > expirationDate) {
|
||||
if (!expirationDate || parsed > expirationDate)
|
||||
expirationDate = parsed;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (expirationDate && expirationDate.getTime() > Date.now()) {
|
||||
console.log(`[Scraper] Found active cooldown until: ${expirationDate.toISOString()}`);
|
||||
return {
|
||||
isActive: true,
|
||||
expiresAt: expirationDate
|
||||
};
|
||||
return { isActive: true, expiresAt: expirationDate };
|
||||
}
|
||||
const content = $('#personal_game_data_content').text();
|
||||
if (content.includes('Competitive Cooldown') || content.includes('Your account is currently')) {
|
||||
@@ -90,8 +95,10 @@ const scrapeCooldown = async (steamId, steamLoginSecure) => {
|
||||
return { isActive: false };
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`[Scraper] Error for ${steamId}:`, error.message);
|
||||
throw error;
|
||||
if (error instanceof SteamAuthError)
|
||||
throw error;
|
||||
console.error(`[Scraper] Network/Internal Error for ${steamId}:`, error.message);
|
||||
throw error; // Generic errors don't trigger re-auth
|
||||
}
|
||||
};
|
||||
exports.scrapeCooldown = scrapeCooldown;
|
||||
|
||||
Reference in New Issue
Block a user