well it 'works' but blocked by cloudflare

This commit is contained in:
bootunloader
2026-01-01 20:00:23 +02:00
parent 9fa4a0c113
commit 4d5bea3dce
9 changed files with 798 additions and 75 deletions

View File

@@ -1,5 +1,5 @@
import { getULID, sleep } from "$lib/utils";
import { constants } from "$lib/utils/constants";
import { baseDistributorId, constants } from "$lib/utils/constants";
import type { BookingEntry, Draw, LooseApiUser } from "$lib/utils/data.types";
import { rng } from "$lib/utils/rng";
// import fs from "fs";
@@ -15,7 +15,7 @@ import { rng } from "$lib/utils/rng";
export const testIfSessionIsValid = async (jwt: string) => {
try {
const res = await fetch(
`${constants.PROXY_API_URL}/v1/user/get-balance?userId=6339&authorization=${encodeURIComponent(jwt)}`,
`${constants.PROXY_API_URL}/v1/user/get-balance?userId=${baseDistributorId}&authorization=${encodeURIComponent(jwt)}`,
{
headers: {
"Content-Type": "application/json",
@@ -297,7 +297,7 @@ export const mockGetUserData = async (
first: f,
second: s,
dealerId: userIds[rng(0, userIds.length - 1)],
distributorId: 6339,
distributorId: baseDistributorId,
drawId: drawId,
number: rng(0, 9999).toString(),
requestId: new Date().getTime().toString(),

View File

@@ -1,3 +1,5 @@
import { getDefaultTotals, getULID } from "$lib/utils";
import { baseDistributorId } from "$lib/utils/constants";
import type {
BookingEntry,
FSTotals,
@@ -7,9 +9,6 @@ import type {
ReducedFinalSheetRow,
ServerError,
} from "$lib/utils/data.types";
import { dbApiData } from "./db/apidata.db";
import { redis } from "./connectors/redis";
import { getDefaultTotals, getULID } from "$lib/utils";
import {
calculatePrize,
calculateProfit,
@@ -18,17 +17,16 @@ import {
getCommisionAmt,
getLexiCode,
getLexiCodeCacheObject,
getNoOfDigits,
getNetRate,
getNoOfDigits,
} from "$lib/utils/finalsheet.utils";
import { redis } from "./connectors/redis";
import { dbApiData } from "./db/apidata.db";
export const getReducedFinalSheet = async (fsData: ReducedFinalSheetData) => {
const bookingEntries = await dbApiData.getBookingEntriesByDraw(
fsData.date,
fsData.drawId
);
const bookingEntries = await dbApiData.getBookingEntriesByDraw(fsData.date, fsData.drawId);
console.log(
`[...] Got ${bookingEntries.length} booking entries for ${fsData.date}, draw ${fsData.drawId}`
`[...] Got ${bookingEntries.length} booking entries for ${fsData.date}, draw ${fsData.drawId}`,
);
const lexiCodeCache = await getLexiCodeCache();
const { sheetCache, totals, failed } = await getSheetCache(bookingEntries);
@@ -68,8 +66,7 @@ export const getReducedFinalSheet = async (fsData: ReducedFinalSheetData) => {
if (child.lexiCode !== "abcd") {
continue;
}
fsRow.frequencies[child.lexiCode][each] =
sheetCache[child.number].frequency[each];
fsRow.frequencies[child.lexiCode][each] = sheetCache[child.number].frequency[each];
}
}
@@ -77,10 +74,7 @@ export const getReducedFinalSheet = async (fsData: ReducedFinalSheetData) => {
fsRow.frequency[each] = vals.frequency[each];
fsRow.rate[each] = vals.rate[each];
fsRow.prize[each] = vals.prize[each];
fsRow.profit[each] = calculateProfit(
totals.netRate[each],
vals.prize[each]
);
fsRow.profit[each] = calculateProfit(totals.netRate[each], vals.prize[each]);
}
if (fsRow.rate.first > highestRate.first) {
highestRate.first = fsRow.rate.first;
@@ -96,11 +90,7 @@ export const getReducedFinalSheet = async (fsData: ReducedFinalSheetData) => {
return { ok: true, errors: [] as ServerError };
};
export const getTargetFSRow = async (
drawId: string,
date: string,
number: string
) => {
export const getTargetFSRow = async (drawId: string, date: string, number: string) => {
const bookingEntries = await dbApiData.getBookingEntriesByDraw(date, drawId);
const lexiCodeCache = await getLexiCodeCache();
const { sheetCache, totals, failed } = await getSheetCache(bookingEntries);
@@ -135,10 +125,7 @@ export const getTargetFSRow = async (
fsRow.frequency[each] = vals.frequency[each];
fsRow.rate[each] = vals.rate[each];
fsRow.prize[each] = vals.prize[each];
fsRow.profit[each] = calculateProfit(
totals.netRate[each],
vals.prize[each]
);
fsRow.profit[each] = calculateProfit(totals.netRate[each], vals.prize[each]);
}
if (fsRow.rate.first > highestRate.first) {
highestRate.first = fsRow.rate.first;
@@ -175,7 +162,7 @@ const getSheetCache = async (bookingEntries: BookingEntry[]) => {
sheetCache[no].rate[each],
lexiCode,
each,
getNoOfDigits(lexiCode)
getNoOfDigits(lexiCode),
);
}
}
@@ -222,16 +209,13 @@ const getCachedReducedFinalSheet = async (date: string, drawId: string) => {
const setCachedReducedFinalSheet = async (
date: string,
drawId: string,
data: ReducedFinalSheetData
data: ReducedFinalSheetData,
) => {
const key = `cfinalsheet:${date}:${drawId}`;
await redis.setex(key, 3600 * 24, JSON.stringify(data));
};
export const deleteCachedReducedFinalSheet = async (
date: string,
drawId: string
) => {
export const deleteCachedReducedFinalSheet = async (date: string, drawId: string) => {
await redis.del(`cfinalsheet:${date}:${drawId}`);
};
@@ -260,7 +244,7 @@ export const getTestBookingData = async (drawId: string, date: string) => {
dealerId: 4677,
sheetId: "test",
requestId: getULID(),
distributorId: 6339,
distributorId: baseDistributorId,
changedBalance: 0,
} as BookingEntry;
out.push(entry);

View File

@@ -1,3 +1,6 @@
// Older/legacy/dead baseDistributorId : 6339
export const baseDistributorId = 178;
export const constants = {
SESSION_KEY_NAME: "SID",
SESSION_EXPIRE_TIME_MS: 6 * 60 * 60 * 1000,