Skip to content

Commit

Permalink
Merge pull request #322 from quark-zju/wexin-compat
Browse files Browse the repository at this point in the history
fix: 微信 Android 内置浏览器兼容性
  • Loading branch information
Yidadaa authored Apr 2, 2023
2 parents d54c983 + cd5f8f7 commit a64c438
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
6 changes: 4 additions & 2 deletions app/api/openai/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { requestOpenai } from "../common";

async function makeRequest(req: NextRequest) {
try {
const res = await requestOpenai(req);
return new Response(res.body);
const api = await requestOpenai(req);
const res = new NextResponse(api.body);
res.headers.set('Content-Type', 'application/json');
return res;
} catch (e) {
console.error("[OpenAI] ", req.body, e);
return NextResponse.json(
Expand Down
4 changes: 4 additions & 0 deletions app/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import type { ChatRequest, ChatReponse } from "./api/openai/typing";
import { filterConfig, Message, ModelConfig, useAccessStore } from "./store";
import Locale from "./locales";

if (!Array.prototype.at) {
require('array.prototype.at/auto');
}

const TIME_OUT_MS = 30000;

const makeRequestParam = (
Expand Down
4 changes: 4 additions & 0 deletions app/store/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { trimTopic } from "../utils";

import Locale from "../locales";

if (!Array.prototype.at) {
require('array.prototype.at/auto');
}

export type Message = ChatCompletionResponseMessage & {
date: string;
streaming?: boolean;
Expand Down
10 changes: 1 addition & 9 deletions app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@ import { showToast } from "./components/ui-lib";
import Locale from "./locales";

export function trimTopic(topic: string) {
const s = topic.split("");
let lastChar = s.at(-1); // 获取 s 的最后一个字符
let pattern = /[,.!?]/; // 定义匹配中文和英文标点符号的正则表达式
while (lastChar && pattern.test(lastChar!)) {
s.pop();
lastChar = s.at(-1);
}

return s.join("");
return topic.replace(/[,.!?]*$/, "");
}

export function copyToClipboard(text: string) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-markdown": "^8.0.5",
"remark-breaks": "^3.0.2",
"rehype-katex": "^6.0.2",
"rehype-prism-plus": "^1.5.1",
"remark-breaks": "^3.0.2",
"remark-gfm": "^3.0.1",
"remark-math": "^5.1.1",
"sass": "^1.59.2",
Expand All @@ -39,6 +39,7 @@
"@types/react-dom": "^18.0.11",
"@types/react-katex": "^3.0.0",
"@types/spark-md5": "^3.0.2",
"array.prototype.at": "^1.1.1",
"cross-env": "^7.0.3",
"eslint": "^8.36.0",
"eslint-config-next": "13.2.3",
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,16 @@ array-union@^2.1.0:
resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d"
integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==

array.prototype.at@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/array.prototype.at/-/array.prototype.at-1.1.1.tgz#6deda3cd3c704afa16361387ea344e0b8d8831b5"
integrity sha512-n/wYNLJy/fVEU9EGPt2ww920hy1XX3XB2yTREFy1QsxctBgQV/tZIwg1G8jVxELna4pLCzg/xvvS/DDXtI4NNg==
dependencies:
call-bind "^1.0.2"
define-properties "^1.1.4"
es-abstract "^1.20.4"
es-shim-unscopables "^1.0.0"

array.prototype.flat@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/array.prototype.flat/-/array.prototype.flat-1.3.1.tgz#ffc6576a7ca3efc2f46a143b9d1dda9b4b3cf5e2"
Expand Down

1 comment on commit a64c438

@vercel
Copy link

@vercel vercel bot commented on a64c438 Apr 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.