Skip to content

Commit

Permalink
Merge pull request ChatGPTNextWeb#5171 from ConnectAI-E/feature/tencent
Browse files Browse the repository at this point in the history
Feature/tencent
  • Loading branch information
Dogtiti authored Aug 2, 2024
2 parents b3219f5 + feaa6f9 commit 67a90ff
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/api/tencent/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 6 additions & 3 deletions app/utils/tencent.ts
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"lodash-es": "^4.17.21",
Expand Down
15 changes: 14 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3756,6 +3756,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"
Expand Down Expand Up @@ -3919,7 +3927,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==
Expand Down Expand Up @@ -4911,6 +4919,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"
Expand Down

0 comments on commit 67a90ff

Please sign in to comment.