From 65e1066b4522edafcca432ddb25cdf1a17d4217b Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Fri, 26 Jul 2024 13:37:33 +0200 Subject: [PATCH] clean code --- src/hooks.server.ts | 19 ++++++++- src/lib/components/AddPortfolio.svelte | 16 +------- src/lib/components/AnalystEstimate.svelte | 19 ++------- src/lib/components/AnalystInsight.svelte | 23 ++--------- src/lib/components/BorrowedShare.svelte | 21 ++-------- src/lib/components/ClinicalTrial.svelte | 21 ++-------- src/lib/components/CommentSection.svelte | 20 ++------- src/lib/components/FailToDeliver.svelte | 21 ++-------- src/lib/components/GovernmentContract.svelte | 20 ++------- src/lib/components/RevenueSegmentation.svelte | 19 ++------- src/lib/components/Searchbar.svelte | 4 +- src/lib/components/ShareStatistics.svelte | 22 ++-------- src/lib/components/Swap.svelte | 21 ++-------- src/lib/components/TrendAnalysis.svelte | 20 ++------- src/lib/components/VaR.svelte | 20 ++------- src/routes/+layout.server.ts | 6 +++ .../stocks/[tickerID]/+layout.server.ts | 41 +++++++++---------- src/routes/stocks/[tickerID]/+layout.svelte | 30 +++----------- src/routes/stocks/[tickerID]/+layout.ts | 1 + src/routes/stocks/[tickerID]/+page.svelte | 25 +++-------- src/routes/stocks/[tickerID]/stats/+page.ts | 24 ++++------- .../[tickerID]/stats/employees/+page.ts | 22 +++------- 22 files changed, 115 insertions(+), 320 deletions(-) diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 8e0f3f6d..496f816d 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -22,14 +22,23 @@ export const handle = async ({ event, resolve }) => { event?.request?.headers?.get('x-vercel-id') ?? 'fra1::fra1::8t4xg-1700258428633-157d82fdfcc7', ); - const userRegion = event?.locals?.region?.split("::")?.at(0)?.split("::")?.at(0) + const userRegion = event?.locals?.region?.split("::")?.at(0)?.split("::")?.at(0) || ''; + + // Set a default API URL + let pbUrl = import.meta.env.VITE_EU_POCKETBASE_URL; + let apiURL = import.meta.env.VITE_EU_API_URL; + let fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL; + let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY; - let pbUrl = import.meta.env.VITE_EU_POCKETBASE_URL; // Set a default API URL if (usRegion?.includes(userRegion)) { pbUrl = import.meta.env.VITE_USEAST_POCKETBASE_URL; + apiURL = import.meta.env.VITE_USEAST_API_URL; + fastifyURL = import.meta.env.VITE_USEAST_FASTIFY_URL; } else { pbUrl = import.meta.env.VITE_EU_POCKETBASE_URL; + apiURL = import.meta.env.VITE_EU_API_URL; + fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL; } @@ -42,10 +51,16 @@ export const handle = async ({ event, resolve }) => { if (event?.locals?.pb?.authStore?.isValid) { await event?.locals?.pb?.collection('users')?.authRefresh(); event.locals.user = serializeNonPOJOs(event?.locals?.pb?.authStore?.model); + event.locals.apiURL = apiURL; + event.locals.fastifyURL = fastifyURL; + event.locals.apiKey = apiKey; } } catch(_) { event?.locals?.pb?.authStore?.clear(); event.locals.user = undefined; + event.locals.apiURL = apiURL; + event.locals.fastifyURL = fastifyURL; + event.locals.apiKey = apiKey; } diff --git a/src/lib/components/AddPortfolio.svelte b/src/lib/components/AddPortfolio.svelte index 5ad67b3f..a41a4b4c 100644 --- a/src/lib/components/AddPortfolio.svelte +++ b/src/lib/components/AddPortfolio.svelte @@ -1,22 +1,10 @@