Skip to content

Commit

Permalink
Update _worker.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jyx04 authored Jun 9, 2024
1 parent 8eee4ec commit ebb008c
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions _worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,7 @@ async function handleUsageRequest(request) {
const htmlResponse = await generateTableHTML(usersData, queryType);
return new Response(htmlResponse, { headers: { 'Content-Type': 'text/html' } });
} else {
const accountNumber = await getTableToCheckAccountNumber(adminUsername);
const accountNumber = await getTableToCheckAccountNumber(adminUsername, queryType);
const accessToken = await KV.get(`at_${accountNumber}`) || '1';
const shareToken = await getToCheckShareToken(adminUsername,accessToken);
const queryLimit = await handleQueryRequest(accessToken,shareToken);
Expand All @@ -2131,7 +2131,7 @@ async function processBatchUsers(users, queryType) {
}

async function processSingleUser(user, queryType) {
const accountNumber = await getTableToCheckAccountNumber(user);
const accountNumber = await getTableToCheckAccountNumber(user, queryType);
const accessToken = await KV.get(`at_${accountNumber}`) || '1';
const shareToken = await getToCheckShareToken(user, accessToken);
const usage = await queryLimits(accessToken, shareToken);
Expand All @@ -2153,10 +2153,9 @@ function parseUsage(usage) {
};
}

async function getTableToCheckAccountNumber(userName) {
const logs = ['FreeLoginLogs', 'PlusLoginLogs'];
for (const log of logs) {
const lastLoginLogs = await KV.get(log);
async function getTableToCheckAccountNumber(userName, queryType) {
const logs = queryType === 'plus' ? ['PlusLoginLogs'] : ['FreeLoginLogs'];
const lastLoginLogs = await KV.get(logs);
if (lastLoginLogs) {
const logArray = JSON.parse(lastLoginLogs);
const userLogs = logArray.filter(log => log.user === userName);
Expand All @@ -2165,7 +2164,6 @@ async function getTableToCheckAccountNumber(userName) {
return lastAccount;
}
}
}
return 'Unknown';
}

Expand Down

0 comments on commit ebb008c

Please sign in to comment.