From ec90332fc583c1f1ba1056f75eca43e7ce37c07d Mon Sep 17 00:00:00 2001 From: Angelo Reale <12191809+angeloreale@users.noreply.github.com> Date: Tue, 27 Aug 2024 02:48:16 +0100 Subject: [PATCH 1/4] ar(fix) bots shield --- src/app/api/v1/user/route.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/app/api/v1/user/route.ts b/src/app/api/v1/user/route.ts index 6298eff7..813f8a04 100644 --- a/src/app/api/v1/user/route.ts +++ b/src/app/api/v1/user/route.ts @@ -22,7 +22,12 @@ const generateErrorResponse = (e: any, status: number) => { // export const dynamic = 'force-static'; export async function POST(request: CombineRequest) { - const isHealthCheck = request?.headers?.get('x-dp-keepalive') === process.env.NEXUS_KEEPALIVE; + const healthSecret = + request?.headers?.get('x-dp-keepalive') || + request?.cookies?.toString().split('dp-health-check=')[1].split(';')[0] || + request?.headers?.get('cookies').toString().split('dp-health-check=')[1].split(';')[0]; + const isHealthCheck = healthSecret === process.env.NEXUS_KEEPALIVE; + console.log({ healthSecret }); if (isHealthCheck) { try { await GetPrivateCommonAbilities({}); From a1aab149db6b4640c8d3f427c410827e77269fbc Mon Sep 17 00:00:00 2001 From: Angelo Reale <12191809+angeloreale@users.noreply.github.com> Date: Tue, 27 Aug 2024 02:50:53 +0100 Subject: [PATCH 2/4] ar(fix) bots shield --- src/app/api/v1/user/route.ts | 44 +++++++++++++++++------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/app/api/v1/user/route.ts b/src/app/api/v1/user/route.ts index 813f8a04..cdc3b52d 100644 --- a/src/app/api/v1/user/route.ts +++ b/src/app/api/v1/user/route.ts @@ -45,17 +45,16 @@ export async function POST(request: CombineRequest) { } } - const cookies = request?.cookies?.toString() || request?.headers?.get('cookies'); - const session = await GetSession({ cookies: cookies || '' }); - const user = session?.user; + try { + const cookies = request?.cookies?.toString() || request?.headers?.get('cookies'); + const session = await GetSession({ cookies: cookies || '' }); + const user = session?.user; - const body = await request?.json(); - const action = body?.action; - // const listings = body?.action; + const body = await request?.json(); + const action = body?.action; - if (!!user && !!action) { - const payload = { data: {} }; - try { + if (!!user && !!action) { + const payload = { data: {} }; if (action === 'get-own-abilities') { payload.data = await GetPrivateAbilities({ filters: ['user'], user }); } else if (action === 'get-own-services') { @@ -63,23 +62,22 @@ export async function POST(request: CombineRequest) { } else { throw new Error('Code 000/1: No specified action'); } - } catch (e) { - return NextResponse.json(generateErrorResponse(e, 400), { status: 400 }); + return NextResponse.json( + { + ok: true, + status: 200, + data: payload.data, + }, + { + status: 200, + }, + ); } - return NextResponse.json( - { - ok: true, - status: 200, - data: payload.data, - }, - { - status: 200, - }, - ); + return NextResponse.json(generateErrorResponse({ message: 'Code 000: Malformed request' }, 400), { status: 400 }); + } catch (e) { + return NextResponse.json(generateErrorResponse(e, 400), { status: 400 }); } - - return NextResponse.json(generateErrorResponse({ message: 'Code 000: Malformed request' }, 400), { status: 400 }); } export async function PATCH(request: CombineRequest) { From 36f9049919f7f8af30c0cbb3049b0309f166d175 Mon Sep 17 00:00:00 2001 From: Angelo Reale <12191809+angeloreale@users.noreply.github.com> Date: Tue, 27 Aug 2024 02:52:07 +0100 Subject: [PATCH 3/4] ar(fix) bots shield --- src/app/api/v1/user/route.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/api/v1/user/route.ts b/src/app/api/v1/user/route.ts index cdc3b52d..9783b678 100644 --- a/src/app/api/v1/user/route.ts +++ b/src/app/api/v1/user/route.ts @@ -27,7 +27,7 @@ export async function POST(request: CombineRequest) { request?.cookies?.toString().split('dp-health-check=')[1].split(';')[0] || request?.headers?.get('cookies').toString().split('dp-health-check=')[1].split(';')[0]; const isHealthCheck = healthSecret === process.env.NEXUS_KEEPALIVE; - console.log({ healthSecret }); + if (isHealthCheck) { try { await GetPrivateCommonAbilities({}); From 200021e9aab35ec7a1bdebd707a8458b14029d49 Mon Sep 17 00:00:00 2001 From: Angelo Reale <12191809+angeloreale@users.noreply.github.com> Date: Tue, 27 Aug 2024 02:56:55 +0100 Subject: [PATCH 4/4] ar(fix) bots shield --- src/app/api/v1/user/route.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/api/v1/user/route.ts b/src/app/api/v1/user/route.ts index 9783b678..73a86bf0 100644 --- a/src/app/api/v1/user/route.ts +++ b/src/app/api/v1/user/route.ts @@ -24,8 +24,9 @@ const generateErrorResponse = (e: any, status: number) => { export async function POST(request: CombineRequest) { const healthSecret = request?.headers?.get('x-dp-keepalive') || - request?.cookies?.toString().split('dp-health-check=')[1].split(';')[0] || - request?.headers?.get('cookies').toString().split('dp-health-check=')[1].split(';')[0]; + request?.cookies?.toString()?.split('dp-health-check=')[1].split(';')[0] || + request?.headers?.get('cookies')?.toString()?.split('dp-health-check=')[1].split(';')[0] || + ''; const isHealthCheck = healthSecret === process.env.NEXUS_KEEPALIVE; if (isHealthCheck) {