diff --git a/.env.local.example b/.env.local.example index 4592c7f4c..93672ab4d 100644 --- a/.env.local.example +++ b/.env.local.example @@ -44,4 +44,4 @@ AUTH_URL="$PUBLIC_URL/api/web/auth" NEXTAUTH_URL="$PUBLIC_URL/api/web/auth" GOOGLE_STATIC_MAP_KEY="" -GOOGLE_STATIC_MAP_SECRET="" +GOOGLE_STATIC_MAP_SIGNATURE_SECRETT="" diff --git a/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx index cb823d655..248d37f47 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx @@ -14,7 +14,7 @@ import { LangParams, PageArgs } from "@/types/params" export default async function SelectHotelPage({ params, }: PageArgs) { - const { formatMessage } = await getIntl() + const intl = await getIntl() const { attributes } = await serverClient().hotel.getHotel({ hotelId: "d98c7ab1-ebaa-4102-b351-758daf1ddf55", @@ -44,7 +44,7 @@ export default async function SelectHotelPage({ variant="underscored" href="#" > - {formatMessage({ id: "Show map" })} + {intl.formatMessage({ id: "Show map" })} diff --git a/components/Maps/StaticMap/index.tsx b/components/Maps/StaticMap/index.tsx index 33ae1afb5..833717833 100644 --- a/components/Maps/StaticMap/index.tsx +++ b/components/Maps/StaticMap/index.tsx @@ -1,6 +1,5 @@ /* eslint-disable @next/next/no-img-element */ -import crypto from "crypto" -import url from "url" +import crypto from "node:crypto" import { env } from "@/env/server" @@ -22,15 +21,6 @@ function encodeBase64Hash(key: Buffer, data: string) { return crypto.createHmac("sha1", key).update(data).digest("base64") } -function createRequestUrl(path: string, secret: string) { - const uri = new URL(path) - const safeSecret = decodeBase64Hash(removeWebSafe(secret)) - const hashedSignature = makeWebSafe( - encodeBase64Hash(safeSecret, uri.pathname + uri.search) - ) - return url.format(uri) + "&signature=" + hashedSignature -} - export default function StaticMap({ city, width, @@ -39,13 +29,18 @@ export default function StaticMap({ mapType, }: StaticMapProps) { const key = env.GOOGLE_STATIC_MAP_KEY - const secret = env.GOOGLE_STATIC_MAP_SECRET - const url = `https://maps.googleapis.com/maps/api/staticmap?center=${city}&zoom=${zoomLevel}&size=${width}x${height}&maptype=${mapType}&key=${key}` + const secret = env.GOOGLE_STATIC_MAP_SIGNATURE_SECRET + const safeSecret = decodeBase64Hash(removeWebSafe(secret)) - return ( - {`Map + const url = new URL( + `https://maps.googleapis.com/maps/api/staticmap?center=${city}&zoom=${zoomLevel}&size=${width}x${height}&maptype=${mapType}&key=${key}` ) + + const hashedSignature = makeWebSafe( + encodeBase64Hash(safeSecret, url.pathname + url.search) + ) + + const src = url.toString() + "&signature=" + hashedSignature + + return {`Map } diff --git a/env/server.ts b/env/server.ts index b4ce26add..866429659 100644 --- a/env/server.ts +++ b/env/server.ts @@ -59,7 +59,7 @@ export const env = createEnv({ WEBVIEW_ENCRYPTION_KEY: z.string(), BOOKING_ENCRYPTION_KEY: z.string(), GOOGLE_STATIC_MAP_KEY: z.string(), - GOOGLE_STATIC_MAP_SECRET: z.string(), + GOOGLE_STATIC_MAP_SIGNATURE_SECRET: z.string(), }, emptyStringAsUndefined: true, runtimeEnv: { @@ -105,6 +105,7 @@ export const env = createEnv({ WEBVIEW_ENCRYPTION_KEY: process.env.WEBVIEW_ENCRYPTION_KEY, BOOKING_ENCRYPTION_KEY: process.env.BOOKING_ENCRYPTION_KEY, GOOGLE_STATIC_MAP_KEY: process.env.GOOGLE_STATIC_MAP_KEY, - GOOGLE_STATIC_MAP_SECRET: process.env.GOOGLE_STATIC_MAP_SECRET, + GOOGLE_STATIC_MAP_SIGNATURE_SECRET: + process.env.GOOGLE_STATIC_MAP_SIGNATURE_SECRET, }, })