mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-08-08 15:46:06 +08:00
Merge pull request #322 from quark-zju/wexin-compat
fix: 微信 Android 内置浏览器兼容性
This commit is contained in:
@@ -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(
|
||||
|
@@ -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 = (
|
||||
|
@@ -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;
|
||||
|
10
app/utils.ts
10
app/utils.ts
@@ -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) {
|
||||
|
Reference in New Issue
Block a user