improve: cookie test and activity scan range

This commit is contained in:
JamesFlare1212
2025-05-09 20:17:06 -04:00
parent f7252345f3
commit cf0e5532d6
3 changed files with 38 additions and 22 deletions

View File

@@ -76,25 +76,39 @@ async function clearCookieCache() {
async function testCookieValidity(cookieString) { async function testCookieValidity(cookieString) {
if (!cookieString) return false; if (!cookieString) return false;
logger.debug("Testing cookie validity..."); logger.debug("Testing cookie validity...");
try {
const url = 'https://engage.nkcswx.cn/Services/ActivitiesService.asmx/GetActivityDetails'; const MAX_RETRIES = 3;
const headers = { let attempt = 0;
'Content-Type': 'application/json; charset=UTF-8',
'Cookie': cookieString, while (attempt < MAX_RETRIES) {
'User-Agent': 'Mozilla/5.0 (Node.js DSAS-CCA get-activity Module)', try {
}; attempt++;
const payload = { "activityID": "3350" }; const url = 'https://engage.nkcswx.cn/Services/ActivitiesService.asmx/GetActivityDetails';
await axios.post(url, payload, { headers, timeout: 10000 }); const headers = {
logger.debug("Cookie test successful (API responded 2xx). Cookie is valid."); 'Content-Type': 'application/json; charset=UTF-8',
return true; 'Cookie': cookieString,
} catch (error) { 'User-Agent': 'Mozilla/5.0 (Node.js DSAS-CCA get-activity Module)',
logger.warn("Cookie validity test failed."); };
if (error.response) { const payload = { "activityID": "3350" };
logger.warn(`Cookie test API response status: ${error.response.status}. Cookie is likely invalid or expired.`);
} else { logger.debug(`Attempt ${attempt}/${MAX_RETRIES}`);
logger.warn(`Cookie test failed due to network or other error: ${error.message}`); await axios.post(url, payload, { headers, timeout: 20000 });
logger.debug("Cookie test successful (API responded 2xx). Cookie is valid.");
return true;
} catch (error) {
logger.warn(`Cookie validity test failed (attempt ${attempt}/${MAX_RETRIES}).`);
if (error.response) {
logger.warn(`Cookie test API response status: ${error.response.status}.`);
} else {
logger.warn(`Network/other error: ${error.message}`);
}
if (attempt >= MAX_RETRIES) {
logger.warn("Max retries reached. Cookie is likely invalid or expired.");
return false;
}
} }
return false;
} }
} }

View File

@@ -10,8 +10,9 @@ S3_SECRET_ACCESS_KEY=
S3_REGION= S3_REGION=
S3_PUBLIC_URL_PREFIX=files S3_PUBLIC_URL_PREFIX=files
REDIS_URL=redis://:dsas-cca@redis:6379 REDIS_URL=redis://:dsas-cca@redis:6379
MAX_ACTIVITY_ID_SCAN=9999 MIN_ACTIVITY_ID_SCAN=3000
MAX_ACTIVITY_ID_SCAN=8000
CONCURRENT_API_CALLS=16 CONCURRENT_API_CALLS=16
STAFF_UPDATE_INTERVAL_MINS=360 STAFF_UPDATE_INTERVAL_MINS=360
CLUB_UPDATE_INTERVAL_MINS=360 CLUB_UPDATE_INTERVAL_MINS=360
LOG_LEVEL=info # Example: 'debug', 'info', 'warn', 'error' LOG_LEVEL=info # Example: 'debug', 'info', 'warn', 'error'

View File

@@ -20,6 +20,7 @@ dotenv.config();
const USERNAME = process.env.API_USERNAME; const USERNAME = process.env.API_USERNAME;
const PASSWORD = process.env.API_PASSWORD; const PASSWORD = process.env.API_PASSWORD;
const MIN_ACTIVITY_ID_SCAN = parseInt(process.env.MIN_ACTIVITY_ID_SCAN || '0', 10);
const MAX_ACTIVITY_ID_SCAN = parseInt(process.env.MAX_ACTIVITY_ID_SCAN || '9999', 10); const MAX_ACTIVITY_ID_SCAN = parseInt(process.env.MAX_ACTIVITY_ID_SCAN || '9999', 10);
const CONCURRENT_API_CALLS = parseInt(process.env.CONCURRENT_API_CALLS || '10', 10); const CONCURRENT_API_CALLS = parseInt(process.env.CONCURRENT_API_CALLS || '10', 10);
const CLUB_UPDATE_INTERVAL_MINS = parseInt(process.env.CLUB_UPDATE_INTERVAL_MINS || '60', 10); const CLUB_UPDATE_INTERVAL_MINS = parseInt(process.env.CLUB_UPDATE_INTERVAL_MINS || '60', 10);
@@ -68,9 +69,9 @@ async function processAndCacheActivity(activityId) {
} }
export async function initializeClubCache() { export async function initializeClubCache() {
logger.info(`Starting initial club cache population up to ID ${MAX_ACTIVITY_ID_SCAN}...`); logger.info(`Starting initial club cache population from ID ${MAX_ACTIVITY_ID_SCAN} to ${MAX_ACTIVITY_ID_SCAN}`);
const promises = []; const promises = [];
for (let i = 0; i <= MAX_ACTIVITY_ID_SCAN; i++) { for (let i = MIN_ACTIVITY_ID_SCAN; i <= MAX_ACTIVITY_ID_SCAN; i++) {
const activityId = String(i); const activityId = String(i);
promises.push(limit(async () => { promises.push(limit(async () => {
const cachedData = await getActivityData(activityId); const cachedData = await getActivityData(activityId);