feat(SW-68): use import instead of require

This commit is contained in:
Fredrik Thorsson
2024-08-12 14:45:32 +02:00
parent 854247e15e
commit 5d18a68d9c

View File

@@ -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
}