Skip to content

Commit a64c438

Browse files
authored
Merge pull request #322 from quark-zju/wexin-compat
fix: 微信 Android 内置浏览器兼容性
2 parents d54c983 + cd5f8f7 commit a64c438

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

app/api/openai/route.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { requestOpenai } from "../common";
33

44
async function makeRequest(req: NextRequest) {
55
try {
6-
const res = await requestOpenai(req);
7-
return new Response(res.body);
6+
const api = await requestOpenai(req);
7+
const res = new NextResponse(api.body);
8+
res.headers.set('Content-Type', 'application/json');
9+
return res;
810
} catch (e) {
911
console.error("[OpenAI] ", req.body, e);
1012
return NextResponse.json(

app/requests.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import type { ChatRequest, ChatReponse } from "./api/openai/typing";
22
import { filterConfig, Message, ModelConfig, useAccessStore } from "./store";
33
import Locale from "./locales";
44

5+
if (!Array.prototype.at) {
6+
require('array.prototype.at/auto');
7+
}
8+
59
const TIME_OUT_MS = 30000;
610

711
const makeRequestParam = (

app/store/app.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import { trimTopic } from "../utils";
1111

1212
import Locale from "../locales";
1313

14+
if (!Array.prototype.at) {
15+
require('array.prototype.at/auto');
16+
}
17+
1418
export type Message = ChatCompletionResponseMessage & {
1519
date: string;
1620
streaming?: boolean;

app/utils.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,7 @@ import { showToast } from "./components/ui-lib";
22
import Locale from "./locales";
33

44
export function trimTopic(topic: string) {
5-
const s = topic.split("");
6-
let lastChar = s.at(-1); // 获取 s 的最后一个字符
7-
let pattern = /[,.!?]/; // 定义匹配中文和英文标点符号的正则表达式
8-
while (lastChar && pattern.test(lastChar!)) {
9-
s.pop();
10-
lastChar = s.at(-1);
11-
}
12-
13-
return s.join("");
5+
return topic.replace(/[,.!?]*$/, "");
146
}
157

168
export function copyToClipboard(text: string) {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
"react": "^18.2.0",
2424
"react-dom": "^18.2.0",
2525
"react-markdown": "^8.0.5",
26-
"remark-breaks": "^3.0.2",
2726
"rehype-katex": "^6.0.2",
2827
"rehype-prism-plus": "^1.5.1",
28+
"remark-breaks": "^3.0.2",
2929
"remark-gfm": "^3.0.1",
3030
"remark-math": "^5.1.1",
3131
"sass": "^1.59.2",
@@ -39,6 +39,7 @@
3939
"@types/react-dom": "^18.0.11",
4040
"@types/react-katex": "^3.0.0",
4141
"@types/spark-md5": "^3.0.2",
42+
"array.prototype.at": "^1.1.1",
4243
"cross-env": "^7.0.3",
4344
"eslint": "^8.36.0",
4445
"eslint-config-next": "13.2.3",

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,16 @@ array-union@^2.1.0:
15701570
resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d"
15711571
integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==
15721572

1573+
array.prototype.at@^1.1.1:
1574+
version "1.1.1"
1575+
resolved "https://registry.yarnpkg.com/array.prototype.at/-/array.prototype.at-1.1.1.tgz#6deda3cd3c704afa16361387ea344e0b8d8831b5"
1576+
integrity sha512-n/wYNLJy/fVEU9EGPt2ww920hy1XX3XB2yTREFy1QsxctBgQV/tZIwg1G8jVxELna4pLCzg/xvvS/DDXtI4NNg==
1577+
dependencies:
1578+
call-bind "^1.0.2"
1579+
define-properties "^1.1.4"
1580+
es-abstract "^1.20.4"
1581+
es-shim-unscopables "^1.0.0"
1582+
15731583
array.prototype.flat@^1.3.1:
15741584
version "1.3.1"
15751585
resolved "https://registry.yarnpkg.com/array.prototype.flat/-/array.prototype.flat-1.3.1.tgz#ffc6576a7ca3efc2f46a143b9d1dda9b4b3cf5e2"

0 commit comments

Comments
 (0)