feat(SW-68): use import instead of require
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user