yuh kuh moar build time fixes #2!!!!! -_-
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
|
import { env } from "$env/dynamic/private";
|
||||||
import { dbApiUser } from "$lib/server/db/apiuser.db";
|
import { dbApiUser } from "$lib/server/db/apiuser.db";
|
||||||
import { getSessionToken } from "$lib/server/external/api.scraping.helpers";
|
import { getSessionToken } from "$lib/server/external/api.scraping.helpers";
|
||||||
|
import { logger } from "$lib/server/logger";
|
||||||
import {
|
import {
|
||||||
isSessionValidInStore,
|
isSessionValidInStore,
|
||||||
removeSessionFromStore,
|
removeSessionFromStore,
|
||||||
@@ -9,16 +11,13 @@ import { getUUID } from "$lib/utils";
|
|||||||
import { constants } from "$lib/utils/constants";
|
import { constants } from "$lib/utils/constants";
|
||||||
import type { ServerError } from "$lib/utils/data.types";
|
import type { ServerError } from "$lib/utils/data.types";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
|
import fetch from "node-fetch";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { createTRPCRouter, protectedProcedure } from "../t";
|
import { createTRPCRouter, protectedProcedure } from "../t";
|
||||||
import { env } from "$env/dynamic/private";
|
|
||||||
import { logger } from "$lib/server/logger";
|
|
||||||
import fetch from "node-fetch";
|
|
||||||
|
|
||||||
|
|
||||||
export const apiAuthRouter = createTRPCRouter({
|
export const apiAuthRouter = createTRPCRouter({
|
||||||
getCaptcha: protectedProcedure.mutation(async () => {
|
getCaptcha: protectedProcedure.mutation(async () => {
|
||||||
const scrapingbeeApiKey = env.SCRAPINGBEE_API_KEY;
|
const scrapingbeeApiKey = env.SCRAPINGBEE_API_KEY ?? "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const uuid = getUUID();
|
const uuid = getUUID();
|
||||||
@@ -39,7 +38,9 @@ export const apiAuthRouter = createTRPCRouter({
|
|||||||
// Clone response before reading to avoid consuming body
|
// Clone response before reading to avoid consuming body
|
||||||
const clonedRes = res.clone();
|
const clonedRes = res.clone();
|
||||||
const errorText = await clonedRes.text().catch(() => "Unknown error");
|
const errorText = await clonedRes.text().catch(() => "Unknown error");
|
||||||
logger.error(`[getCaptcha] ScrapingBee error ${res.status}: ${errorText.substring(0, 200)}`);
|
logger.error(
|
||||||
|
`[getCaptcha] ScrapingBee error ${res.status}: ${errorText.substring(0, 200)}`,
|
||||||
|
);
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "INTERNAL_SERVER_ERROR",
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
message: `Failed to fetch captcha image: ${res.status}`,
|
message: `Failed to fetch captcha image: ${res.status}`,
|
||||||
@@ -51,7 +52,9 @@ export const apiAuthRouter = createTRPCRouter({
|
|||||||
const imageBuffer = Buffer.from(arrayBuffer);
|
const imageBuffer = Buffer.from(arrayBuffer);
|
||||||
const base64String = imageBuffer.toString("base64");
|
const base64String = imageBuffer.toString("base64");
|
||||||
|
|
||||||
logger.info(`[getCaptcha] Successfully fetched captcha image for uuid: ${uuid}, size: ${imageBuffer.length} bytes`);
|
logger.info(
|
||||||
|
`[getCaptcha] Successfully fetched captcha image for uuid: ${uuid}, size: ${imageBuffer.length} bytes`,
|
||||||
|
);
|
||||||
return { id: uuid, image: base64String };
|
return { id: uuid, image: base64String };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error("[getCaptcha] Error getting captcha image", err);
|
logger.error("[getCaptcha] Error getting captcha image", err);
|
||||||
|
|||||||
Reference in New Issue
Block a user