From 5d18a68d9cbac00ba75ef2aa6bd2a6ad77967969 Mon Sep 17 00:00:00 2001 From: Fredrik Thorsson Date: Mon, 12 Aug 2024 14:45:32 +0200 Subject: [PATCH] feat(SW-68): use import instead of require --- components/Maps/StaticMap/index.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/components/Maps/StaticMap/index.tsx b/components/Maps/StaticMap/index.tsx index bf54082ab..33ae1afb5 100644 --- a/components/Maps/StaticMap/index.tsx +++ b/components/Maps/StaticMap/index.tsx @@ -1,11 +1,11 @@ /* eslint-disable @next/next/no-img-element */ +import crypto from "crypto" +import url from "url" + import { env } from "@/env/server" import { StaticMapProps } from "@/types/components/maps/staticMap/staticMap" -const crypto = require("crypto") -const url = require("url") - function removeWebSafe(safeEncodedString: string) { return safeEncodedString.replace(/-/g, "+").replace(/_/g, "/") } @@ -22,10 +22,12 @@ function encodeBase64Hash(key: Buffer, data: string) { return crypto.createHmac("sha1", key).update(data).digest("base64") } -const createRequestUrl = function (path: string, secret: string) { - const uri = url.parse(path) +function createRequestUrl(path: string, secret: string) { + const uri = new URL(path) const safeSecret = decodeBase64Hash(removeWebSafe(secret)) - const hashedSignature = makeWebSafe(encodeBase64Hash(safeSecret, uri.path)) + const hashedSignature = makeWebSafe( + encodeBase64Hash(safeSecret, uri.pathname + uri.search) + ) return url.format(uri) + "&signature=" + hashedSignature }