uhhhh yeah

This commit is contained in:
bootunloader
2025-01-05 12:00:56 +02:00
parent 98dd86bd12
commit 15f2b238b0
3 changed files with 57 additions and 37 deletions

View File

@@ -116,10 +116,18 @@ export async function postDataToApi(payload: {
total,
message,
);
const rj = (await res.json()) as APIRespnose<{
bookDtos: { bookId: string; requestId: number }[];
}>;
if (rj.code === 200 && res.status === 200) {
let rj:
| APIRespnose<{
bookDtos: { bookId: string; requestId: number }[];
}>
| undefined = undefined;
try {
rj = (await res.json()) as any;
} catch (err) {
console.log("Encountered error while parsing post response");
console.log(res.status, err);
}
if (rj && rj.code === 200 && res.status === 200) {
ptr = jumped;
userResponseIds.push(
...rj.data.bookDtos.map((b) => ({
@@ -130,6 +138,8 @@ export async function postDataToApi(payload: {
successResponses++;
break;
}
console.log("Failed to send send post request");
console.log(res.status, rj);
failedResponses++;
tries++;
}
@@ -162,7 +172,8 @@ export async function postDataToApi(payload: {
responsesIds.push(...result.value);
} else {
hasErrors = true;
console.log(`[!] Error processing user: ${result.reason}`);
console.log(`[!] Error processing user`);
console.log(result.reason);
}
});
@@ -210,11 +221,11 @@ async function sendBatchRequest(
"User-Agent": getRandomUserAgent(),
},
body: JSON.stringify({
changedBalance,
closeTime: draw.closeTime,
date: new Date().toISOString().split("T")[0],
dealerId,
drawId: Number(draw.id.split(":")[1]),
closeTime: draw.closeTime,
date: new Date().toISOString().split("T")[0],
changedBalance,
insertData: body,
}),
});
@@ -227,24 +238,31 @@ async function mockSendBatchRequest(
changedBalance: number,
body: string,
) {
console.log("----- Sending batch request ------");
console.log(session);
console.log(dealerId);
console.log(draw);
console.log(changedBalance);
console.log(body);
console.log("----------------------------------");
// between 5 to 20 ms
await sleep(Math.floor(Math.random() * 1000) + 50);
if (Math.random() < 0.005) {
return new Response(
JSON.stringify({
code: 500,
success: false,
message: "Failed",
data: {},
time: new Date().toISOString(),
}),
{
status: 500,
headers: { "Content-Type": "application/json" },
statusText: "Failed",
},
);
}
// if (Math.random() < 0.005) {
// return new Response(
// JSON.stringify({
// code: 500,
// success: false,
// message: "Failed",
// data: {},
// time: new Date().toISOString(),
// }),
// {
// status: 500,
// headers: { "Content-Type": "application/json" },
// statusText: "Failed",
// },
// );
// }
return new Response(
JSON.stringify({
code: 200,
@@ -291,10 +309,10 @@ async function deleteAllBookedEntries({
"User-Agent": getRandomUserAgent(),
},
body: JSON.stringify({
bookIds: data.map((e) => e.bookId),
closeTime,
dealerId,
drawId,
closeTime,
bookIds: data.map((e) => e.bookId),
}),
});
}

View File

@@ -139,7 +139,7 @@ export const postDataApiRouter = createTRPCRouter({
errors: [],
};
}
console.log(`[=] ${users} users found`);
console.log(`[=] ${users.length} users found`);
console.log(users);
console.log("[+] Preparing the sessions for posting");
@@ -192,13 +192,15 @@ export const postDataApiRouter = createTRPCRouter({
console.log(`[+] Posting ${data.length} entries to the API`);
let ts = new Date().getTime();
const res = await postDataToApi({
sessions: userSessions,
data,
users,
draw,
});
console.timeEnd("Time taken to post data to the API");
let done = new Date().getTime();
console.log(`Time taken to post data to the API: ${done - ts} ms`);
if (!res.ok) {
await removePostSession();

View File

@@ -3,15 +3,15 @@ import { vitePreprocess } from "@sveltejs/kit/vite";
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: vitePreprocess(),
kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter(),
},
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: vitePreprocess(),
kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter(),
},
};
export default config;