You are an expert code reviewer. Your task is to analyze the provided code files and provide a comprehensive code review. For each file, consider:

1. Code Quality: Assess readability, maintainability, and adherence to best practices
2. Potential Issues: Identify bugs, security vulnerabilities, or performance concerns
3. Suggestions: Provide specific recommendations for improvements

Format your review as follows:
1. Start with a brief overview of all files
2. For each file, provide:
   - A summary of the file's purpose
   - Key findings (both positive and negative)
   - Specific recommendations
3. End with any overall suggestions for the codebase

Your review should be detailed but concise, focusing on the most important aspects of the code.

Files to review:

File: ./src/core/bypasses/keyrblx.ts
Content:
import { sleep } from "bun";
import { load } from "cheerio";
import { fetch } from "bun";
import { createRegExp, exactly, digit, maybe, oneOrMore } from "magic-regexp";
import { logger } from "../logger";

export async function keyrblx(link: string) {
  return new Promise((resolve) => {
    const now = performance.now();
    let stepsFinished = 0;
    const timeoutId = setTimeout(() => {
      resolve({
        status: "error",
        message: "The client took too long to send the request.",
      });
      return;
    }, 500 * 1000);

    const run = async () => {
      const hwid = new URL(link).searchParams.get("hwid");
      let checkpoint = 1;
      if (!hwid) {
        return {
          status: "error",
          message:
            "Missing HWID. Make sure to include a valid HWID in the 'hwid' parameter.",
        };
      }

      const service = link.split("/")[4].split("?")[0];

      if (!service) {
        return {
          status: "error",
          message:
            "Missing service name. Make sure to include a valid service name in the link.",
        };
      }

      try {
        const resultt = await fetch(`http://localhost:3000/api/v1/scraper`, {
          method: "POST",
          body: JSON.stringify({
            url: `https://keyrblx.com/getkey/${service}?hwid=${hwid}`,
            delayBeforeClose: 3,
            cache: true,
          }),
          headers: {
            "Content-Type": "application/json",
            authorization: `Bearer ${process.env.ADMIN_KEY}`,
          },
        });

        const result = await resultt.json();

        let sleepTime = 3000;

        if (!result.result?.html) {
          return {
            status: "error",
            message:
              "An error occurred while trying to get the key information. This is probably a problem on our side, please report it to the developers.",
          };
        }

        if (result.result.html.includes("__next_error__")) {
          return {
            status: "error",
            message: `The requested service '${service}' does not exist or is not available. Make sure to provide a valid service name in the link.`,
          };
        }

        const isBypassedResult = isBypassed(result.result.html);

        if (isBypassedResult) {
          const timeExpired = getExpireTime(result.result.html);
          return {
            status: "success",
            result: isBypassedResult,
            metadata: {
              expire: timeExpired,
              hwid: hwid,
              service: service,
            },
          };
        }

        const $ = load(result.result.html);

        const turnstileResultt = await fetch(
          `http://localhost:3000/api/v1/turnstile`,
          {
            method: "POST",
            body: JSON.stringify({
              url: `https://keyrblx.com/getkey/${service}?hwid=${hwid}`,
              cache: true,
            }),
            headers: {
              "Content-Type": "application/json",
              authorization: `Bearer ${process.env.ADMIN_KEY}`,
            },
          }
        );

        const turnstileResult = await turnstileResultt.json();

        let cookies = new Set([
          `_ga_MBC0N013D6=GS1.1.1723641691.2.0.1723641708.0.0.0`,
          `_ga=GA1.1.1861358708.1723188904`,
          `dom3ic8zudi28v8lr6fgphwffqoz0j6c=b60a4ab3-22db-4c3f-8b09-fe48a1ee2beb%3A3%3A1`,
          `${service}_hwid=${hwid}`,
        ]);

        const proceed = async (cookies: Set<string>, token?: string) => {
          if (stepsFinished > 11) {
            return {
              status: "error",
              message:
                "The maximum number of steps has been reached without completion. This may be due to changes in KeyRBLX's process or temporary issues.",
            };
          }

          let data: {
            name: string;
            token: string;
            hwid: string;
            provider: string;
          };

          if (token) {
            data = {
              name: `${service}`,
              token,
              hwid,
              provider: `Turnstile`,
            };
          } else {
            const turnstileResultt = await fetch(
              `http://localhost:3000/api/v1/turnstile`,
              {
                method: "POST",
                body: JSON.stringify({
                  url: `https://keyrblx.com/getkey/${service}?hwid=${hwid}`,
                  cache: true,
                  delayBeforeClose: 1000,
                }),
                headers: {
                  "Content-Type": "application/json",
                  authorization: `Bearer ${process.env.ADMIN_KEY}`,
                },
              }
            );
            const turnstileResult = await turnstileResultt.json();
            if (!turnstileResult.result?.token) {
              return {
                status: "error",
                message:
                  "Failed to get turnstile token. This is probably a problem on our side, please report it to the developers.",
              };
            }

            token = turnstileResult.result.token;

            data = {
              name: `${service}`,
              token: turnstileResult.result.token,
              hwid: hwid,
              provider: "Turnstile",
            };
          }

          const encodedData = Object.entries(data)
            .map(
              ([key, value]) =>
                encodeURIComponent(key) +
                "=" +
                encodeURIComponent(value as string)
            )
            .join("&");

          const headers = {
            "User-Agent":
              "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0",
            Accept:
              "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8",
            "Accept-Language": "en-US,en;q=0.5",
            "Accept-Encoding": "gzip, deflate, br, zstd",
            "Content-Type": "application/x-www-form-urlencoded",
            Origin: "https://keyrblx.com",
            Referer: `https://keyrblx.com/getkey/${service}?hwid=${hwid}`,
            Cookie: Array.from(cookies).join("; "),
            "Upgrade-Insecure-Requests": "1",
            "Sec-Fetch-Dest": "document",
            "Sec-Fetch-Mode": "navigate",
            "Sec-Fetch-Site": "same-origin",
            "Sec-Fetch-User": "?1",
            Priority: "u=0, i",
            TE: "trailers",
          };

          const response = await fetch(`https://keyrblx.com/api/captcha`, {
            method: "POST",
            headers,
            body: encodedData,
            redirect: "manual",
          });

          const location = response.headers.get("location");
          if (!location) {
            return {
              status: "error",
              message:
                "Failed to get redirect location. This is probably a problem on our side, please report it to the developers.",
            };
          }

          let bypassed: string;

          if (location.includes("https://link-to")) {
            const bypass = await fetch(
              `https://api.bypass.vip/bypass?url=${location}`
            );
            const data = await bypass.json();
            bypassed = data.result;
          } else {
            bypassed = `https://keyrblx.com/getkey/${service}?step=${checkpoint}`;
            checkpoint++;
            checkpoint++;
          }

          let referer = location.includes("https://link-to")
            ? "https://linkvertise.com/"
            : `https://${new URL(location).hostname}/`;

          if (referer.includes("work")) {
            referer = "https://work.ink/";
          }

          await sleep(sleepTime);

          const resulttt = await fetch(`http://localhost:3000/api/v1/scraper`, {
            method: "POST",
            body: JSON.stringify({
              url: `https://keyrblx.com/getkey/FFJHub?hwid=38412083byte-on-top`,
              delayBeforeClose: 3,
              cache: true,
            }),
            headers: {
              "Content-Type": "application/json",
              authorization: `Bearer ${process.env.ADMIN_KEY}`,
            },
          });

          const resultt = await resulttt.json();

          cookies.add(`cf_clearance=${resultt.result?.metadata?.cf_clearance}`);

          const res = await fetch(bypassed, {
            headers: {
              Date: new Date(Date.now() + 120000).toUTCString(),
              "User-Agent": resultt.result?.metadata?.user_agent!,
              Accept:
                "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8",
              "Accept-Language": "en-US,en;q=0.5",
              "Accept-Encoding": "gzip, deflate, br, zstd",
              Referer: referer,
              Cookie: Array.from(cookies).join("; "),
              "Upgrade-Insecure-Requests": "1",
              "Sec-Fetch-Dest": "document",
              "Sec-Fetch-Mode": "navigate",
              "Sec-Fetch-Site": "cross-site",
              "Sec-Fetch-User": "?1",
              Priority: "u=0, i",
              TE: "trailers",
            },
          });

          const html = await res.text();
          if (html.includes("You gone too fast.")) {
            const $ = load(html);
            const waitTime = Number(
              $(".flex h4").text().match(/\d+/)?.[0] || "0"
            );
            sleepTime = Math.max(sleepTime, waitTime * 1000);
          }

          const isBypassedd = isBypassed(html);
          if (isBypassedd) {
            const timeExpired = getExpireTime(html);
            return {
              status: "success",
              result: isBypassedd,
              metadata: {
                expire: timeExpired,
                hwid: hwid,
                service: service,
              },
            };
          } else {
            stepsFinished++;
            return await proceed(cookies, token);
          }
        };

        const bypassed = await proceed(cookies, turnstileResult.result?.token);

        if (bypassed?.result) {
          return bypassed;
        } else {
          return await keyrblx(link);
        }
      } catch (error) {
        logger.fork("keyrblx").error(error);
        return {
          status: "error",
          message:
            "Unexpected result format. This is probably a problem on our side, please report it to the developers.",
        };
      }
    };

    run()
      .then((result) => {
        clearTimeout(timeoutId);
        resolve(result);
      })
      .catch((error) => {
        logger.fork("keyrblx").error(error);
        clearTimeout(timeoutId);
        resolve({
          status: "error",
          message:
            "Received an error. This is probably a problem on our side, please report it to the developers.",
        });
      });
  });
}

function isBypassed(html: string): string | false {
  const $ = load(html);

  if (html.includes("You successfully")) {
    const input = $('input[aria-invalid="false"]');
    if (input.length > 0) {
      const value = input.attr("value");
      if (value) {
        return value;
      }
    }
    return false;
  }

  return false;
}

const getExpireTime = (html: string): string | null => {
  const regex = createRegExp(
    exactly('\\"time_expired\\"')
      .and(":")
      .and(oneOrMore(digit))
      .and(maybe(".").and(oneOrMore(digit)))
  );

  const match = html.match(regex);
  if (match) {
    const value = match[0]!.split(":")[1].split(".")[0];
    const date = new Date(parseInt(value) * 1000);
    return date.toISOString();
  } else {
    return null;
  }
};



PROMPT: You are an expert code reviewer. Your task is to analyze the provided code files and provide a comprehensive code review. For each file, consider:

1. Code Quality: Assess readability, maintainability, and adherence to best practices
2. Potential Issues: Identify bugs, security vulnerabilities, or performance concerns
3. Suggestions: Provide specific recommendations for improvements

Format your review as follows:
1. Start with a brief overview of all files
2. For each file, provide:
   - A summary of the file's purpose
   - Key findings (both positive and negative)
   - Specific recommendations
3. End with any overall suggestions for the codebase

Your review should be detailed but concise, focusing on the most important aspects of the code.

Files to review:

File: ./src/core/bypasses/keyrblx.ts
Content:
import { sleep } from "bun";
import { load } from "cheerio";
import { fetch } from "bun";
import { createRegExp, exactly, digit, maybe, oneOrMore } from "magic-regexp";
import { logger } from "../logger";

export async function keyrblx(link: string) {
  return new Promise((resolve) => {
    const now = performance.now();
    let stepsFinished = 0;
    const timeoutId = setTimeout(() => {
      resolve({
        status: "error",
        message: "The client took too long to send the request.",
      });
      return;
    }, 500 * 1000);

    const run = async () => {
      const hwid = new URL(link).searchParams.get("hwid");
      let checkpoint = 1;
      if (!hwid) {
        return {
          status: "error",
          message:
            "Missing HWID. Make sure to include a valid HWID in the 'hwid' parameter.",
        };
      }

      const service = link.split("/")[4].split("?")[0];

      if (!service) {
        return {
          status: "error",
          message:
            "Missing service name. Make sure to include a valid service name in the link.",
        };
      }

      try {
        const resultt = await fetch(`http://localhost:3000/api/v1/scraper`, {
          method: "POST",
          body: JSON.stringify({
            url: `https://keyrblx.com/getkey/${service}?hwid=${hwid}`,
            delayBeforeClose: 3,
            cache: true,
          }),
          headers: {
            "Content-Type": "application/json",
            authorization: `Bearer ${process.env.ADMIN_KEY}`,
          },
        });

        const result = await resultt.json();

        let sleepTime = 3000;

        if (!result.result?.html) {
          return {
            status: "error",
            message:
              "An error occurred while trying to get the key information. This is probably a problem on our side, please report it to the developers.",
          };
        }

        if (result.result.html.includes("__next_error__")) {
          return {
            status: "error",
            message: `The requested service '${service}' does not exist or is not available. Make sure to provide a valid service name in the link.`,
          };
        }

        const isBypassedResult = isBypassed(result.result.html);

        if (isBypassedResult) {
          const timeExpired = getExpireTime(result.result.html);
          return {
            status: "success",
            result: isBypassedResult,
            metadata: {
              expire: timeExpired,
              hwid: hwid,
              service: service,
            },
          };
        }

        const $ = load(result.result.html);

        const turnstileResultt = await fetch(
          `http://localhost:3000/api/v1/turnstile`,
          {
            method: "POST",
            body: JSON.stringify({
              url: `https://keyrblx.com/getkey/${service}?hwid=${hwid}`,
              cache: true,
            }),
            headers: {
              "Content-Type": "application/json",
              authorization: `Bearer ${process.env.ADMIN_KEY}`,
            },
          }
        );

        const turnstileResult = await turnstileResultt.json();

        let cookies = new Set([
          `_ga_MBC0N013D6=GS1.1.1723641691.2.0.1723641708.0.0.0`,
          `_ga=GA1.1.1861358708.1723188904`,
          `dom3ic8zudi28v8lr6fgphwffqoz0j6c=b60a4ab3-22db-4c3f-8b09-fe48a1ee2beb%3A3%3A1`,
          `${service}_hwid=${hwid}`,
        ]);

        const proceed = async (cookies: Set<string>, token?: string) => {
          if (stepsFinished > 11) {
            return {
              status: "error",
              message:
                "The maximum number of steps has been reached without completion. This may be due to changes in KeyRBLX's process or temporary issues.",
            };
          }

          let data: {
            name: string;
            token: string;
            hwid: string;
            provider: string;
          };

          if (token) {
            data = {
              name: `${service}`,
              token,
              hwid,
              provider: `Turnstile`,
            };
          } else {
            const turnstileResultt = await fetch(
              `http://localhost:3000/api/v1/turnstile`,
              {
                method: "POST",
                body: JSON.stringify({
                  url: `https://keyrblx.com/getkey/${service}?hwid=${hwid}`,
                  cache: true,
                  delayBeforeClose: 1000,
                }),
                headers: {
                  "Content-Type": "application/json",
                  authorization: `Bearer ${process.env.ADMIN_KEY}`,
                },
              }
            );
            const turnstileResult = await turnstileResultt.json();
            if (!turnstileResult.result?.token) {
              return {
                status: "error",
                message:
                  "Failed to get turnstile token. This is probably a problem on our side, please report it to the developers.",
              };
            }

            token = turnstileResult.result.token;

            data = {
              name: `${service}`,
              token: turnstileResult.result.token,
              hwid: hwid,
              provider: "Turnstile",
            };
          }

          const encodedData = Object.entries(data)
            .map(
              ([key, value]) =>
                encodeURIComponent(key) +
                "=" +
                encodeURIComponent(value as string)
            )
            .join("&");

          const headers = {
            "User-Agent":
              "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0",
            Accept:
              "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8",
            "Accept-Language": "en-US,en;q=0.5",
            "Accept-Encoding": "gzip, deflate, br, zstd",
            "Content-Type": "application/x-www-form-urlencoded",
            Origin: "https://keyrblx.com",
            Referer: `https://keyrblx.com/getkey/${service}?hwid=${hwid}`,
            Cookie: Array.from(cookies).join("; "),
            "Upgrade-Insecure-Requests": "1",
            "Sec-Fetch-Dest": "document",
            "Sec-Fetch-Mode": "navigate",
            "Sec-Fetch-Site": "same-origin",
            "Sec-Fetch-User": "?1",
            Priority: "u=0, i",
            TE: "trailers",
          };

          const response = await fetch(`https://keyrblx.com/api/captcha`, {
            method: "POST",
            headers,
            body: encodedData,
            redirect: "manual",
          });

          const location = response.headers.get("location");
          if (!location) {
            return {
              status: "error",
              message:
                "Failed to get redirect location. This is probably a problem on our side, please report it to the developers.",
            };
          }

          let bypassed: string;

          if (location.includes("https://link-to")) {
            const bypass = await fetch(
              `https://api.bypass.vip/bypass?url=${location}`
            );
            const data = await bypass.json();
            bypassed = data.result;
          } else {
            bypassed = `https://keyrblx.com/getkey/${service}?step=${checkpoint}`;
            checkpoint++;
            checkpoint++;
          }

          let referer = location.includes("https://link-to")
            ? "https://linkvertise.com/"
            : `https://${new URL(location).hostname}/`;

          if (referer.includes("work")) {
            referer = "https://work.ink/";
          }

          await sleep(sleepTime);

          const resulttt = await fetch(`http://localhost:3000/api/v1/scraper`, {
            method: "POST",
            body: JSON.stringify({
              url: `https://keyrblx.com/getkey/FFJHub?hwid=38412083byte-on-top`,
              delayBeforeClose: 3,
              cache: true,
            }),
            headers: {
              "Content-Type": "application/json",
              authorization: `Bearer ${process.env.ADMIN_KEY}`,
            },
          });

          const resultt = await resulttt.json();

          cookies.add(`cf_clearance=${resultt.result?.metadata?.cf_clearance}`);

          const res = await fetch(bypassed, {
            headers: {
              Date: new Date(Date.now() + 120000).toUTCString(),
              "User-Agent": resultt.result?.metadata?.user_agent!,
              Accept:
                "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8",
              "Accept-Language": "en-US,en;q=0.5",
              "Accept-Encoding": "gzip, deflate, br, zstd",
              Referer: referer,
              Cookie: Array.from(cookies).join("; "),
              "Upgrade-Insecure-Requests": "1",
              "Sec-Fetch-Dest": "document",
              "Sec-Fetch-Mode": "navigate",
              "Sec-Fetch-Site": "cross-site",
              "Sec-Fetch-User": "?1",
              Priority: "u=0, i",
              TE: "trailers",
            },
          });

          const html = await res.text();
          if (html.includes("You gone too fast.")) {
            const $ = load(html);
            const waitTime = Number(
              $(".flex h4").text().match(/\d+/)?.[0] || "0"
            );
            sleepTime = Math.max(sleepTime, waitTime * 1000);
          }

          const isBypassedd = isBypassed(html);
          if (isBypassedd) {
            const timeExpired = getExpireTime(html);
            return {
              status: "success",
              result: isBypassedd,
              metadata: {
                expire: timeExpired,
                hwid: hwid,
                service: service,
              },
            };
          } else {
            stepsFinished++;
            return await proceed(cookies, token);
          }
        };

        const bypassed = await proceed(cookies, turnstileResult.result?.token);

        if (bypassed?.result) {
          return bypassed;
        } else {
          return await keyrblx(link);
        }
      } catch (error) {
        logger.fork("keyrblx").error(error);
        return {
          status: "error",
          message:
            "Unexpected result format. This is probably a problem on our side, please report it to the developers.",
        };
      }
    };

    run()
      .then((result) => {
        clearTimeout(timeoutId);
        resolve(result);
      })
      .catch((error) => {
        logger.fork("keyrblx").error(error);
        clearTimeout(timeoutId);
        resolve({
          status: "error",
          message:
            "Received an error. This is probably a problem on our side, please report it to the developers.",
        });
      });
  });
}

function isBypassed(html: string): string | false {
  const $ = load(html);

  if (html.includes("You successfully")) {
    const input = $('input[aria-invalid="false"]');
    if (input.length > 0) {
      const value = input.attr("value");
      if (value) {
        return value;
      }
    }
    return false;
  }

  return false;
}

const getExpireTime = (html: string): string | null => {
  const regex = createRegExp(
    exactly('\\"time_expired\\"')
      .and(":")
      .and(oneOrMore(digit))
      .and(maybe(".").and(oneOrMore(digit)))
  );

  const match = html.match(regex);
  if (match) {
    const value = match[0]!.split(":")[1].split(".")[0];
    const date = new Date(parseInt(value) * 1000);
    return date.toISOString();
  } else {
    return null;
  }
};