From 753bf3b924efe5814e426e69f6963bd6581f65ea Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Fri, 2 Aug 2024 15:55:26 +0800 Subject: [PATCH] hotfix for cf deploy error #5168 --- app/api/tencent/route.ts | 2 +- app/utils/tencent.ts | 9 ++++++--- package.json | 1 + yarn.lock | 15 ++++++++++++++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/api/tencent/route.ts b/app/api/tencent/route.ts index d506d1016d5..885909e7a75 100644 --- a/app/api/tencent/route.ts +++ b/app/api/tencent/route.ts @@ -43,7 +43,7 @@ async function handle( export const GET = handle; export const POST = handle; -export const runtime = "nodejs"; +export const runtime = "edge"; export const preferredRegion = [ "arn1", "bom1", diff --git a/app/utils/tencent.ts b/app/utils/tencent.ts index 019d330b6ff..f0cdd21ee17 100644 --- a/app/utils/tencent.ts +++ b/app/utils/tencent.ts @@ -1,14 +1,17 @@ -import { createHash, createHmac } from "node:crypto"; +import hash from "hash.js"; + // 使用 SHA-256 和 secret 进行 HMAC 加密 function sha256(message: any, secret = "", encoding?: string) { - return createHmac("sha256", secret) + return hash + .hmac(hash.sha256 as any, secret) .update(message) .digest(encoding as any); } // 使用 SHA-256 进行哈希 function getHash(message: any, encoding = "hex") { - return createHash("sha256") + return hash + .sha256() .update(message) .digest(encoding as any); } diff --git a/package.json b/package.json index ed5edb04330..652d4c8760e 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "@vercel/speed-insights": "^1.0.2", "emoji-picker-react": "^4.9.2", "fuse.js": "^7.0.0", + "hash.js": "^1.1.7", "heic2any": "^0.0.4", "html-to-image": "^1.11.11", "mermaid": "^10.6.1", diff --git a/yarn.lock b/yarn.lock index c323a5c38db..ad3b4b4c3d1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3744,6 +3744,14 @@ has@^1.0.3: dependencies: function-bind "^1.1.1" +hash.js@^1.1.7: + version "1.1.7" + resolved "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz#0babca538e8d4ee4a0f8988d68866537a003cf42" + integrity sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA== + dependencies: + inherits "^2.0.3" + minimalistic-assert "^1.0.1" + hast-util-from-dom@^4.0.0: version "4.2.0" resolved "https://registry.yarnpkg.com/hast-util-from-dom/-/hast-util-from-dom-4.2.0.tgz#25836ddecc3cc0849d32749c2a7aec03e94b59a7" @@ -3907,7 +3915,7 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits@2: +inherits@2, inherits@^2.0.3: version "2.0.4" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== @@ -4899,6 +4907,11 @@ mimic-fn@^4.0.0: resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-4.0.0.tgz#60a90550d5cb0b239cca65d893b1a53b29871ecc" integrity sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw== +minimalistic-assert@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7" + integrity sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A== + minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"