Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复 #3928

Closed
wants to merge 6 commits into from
Closed

修复 #3928

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ One-Click to get a well-designed cross-platform ChatGPT web UI, with GPT3, GPT4
[MacOS-image]: https://img.shields.io/badge/-MacOS-black?logo=apple
[Linux-image]: https://img.shields.io/badge/-Linux-333?logo=ubuntu

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FYidadaa%2FChatGPT-Next-Web&env=OPENAI_API_KEY&env=CODE&env=GOOGLE_API_KEY&project-name=chatgpt-next-web&repository-name=ChatGPT-Next-Web)
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fhtmambo%2FChatGPT-Next-Web&env=OPENAI_API_KEY&env=CODE&env=GOOGLE_API_KEY&project-name=chatgpt-next-web&repository-name=ChatGPT-Next-Web)

[![Deploy on Zeabur](https://zeabur.com/button.svg)](https://zeabur.com/templates/ZBUEFA)

Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

1. 准备好你的 [OpenAI API Key](https://platform.openai.com/account/api-keys);
2. 点击右侧按钮开始部署:
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FYidadaa%2FChatGPT-Next-Web&env=OPENAI_API_KEY&env=CODE&env=GOOGLE_API_KEY&project-name=chatgpt-next-web&repository-name=ChatGPT-Next-Web),直接使用 Github 账号登录即可,记得在环境变量页填入 API Key 和[页面访问密码](#配置页面访问密码) CODE;
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fhtmambo%2FChatGPT-Next-Web&env=OPENAI_API_KEY&env=CODE&env=GOOGLE_API_KEY&project-name=chatgpt-next-web&repository-name=ChatGPT-Next-Web),直接使用 Github 账号登录即可,记得在环境变量页填入 API Key 和[页面访问密码](#配置页面访问密码) CODE;
3. 部署完毕后,即可开始使用;
4. (可选)[绑定自定义域名](https://vercel.com/docs/concepts/projects/domains/add-a-domain):Vercel 分配的域名 DNS 在某些区域被污染了,绑定自定义域名即可直连。

Expand Down
21 changes: 21 additions & 0 deletions app/store/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ export const useMaskStore = createPersistStore(
(set, get) => ({
create(mask?: Partial<Mask>) {
const masks = get().masks;
// 检查要导入的项目是否重复
for (let existingMask of Object.values(masks)) {
if (existingMask.name === mask?.name) {
if (
JSON.stringify(existingMask.context) ===
JSON.stringify(mask?.context)
) {
console.log(
"A mask with the same name and context already exists.",
);
return existingMask;
} else {
// 只有name重复,给name加上今天的日期和时间
let now = new Date();
let year = String(now.getFullYear()).slice(-2); // 获取年份的最后两位
mask.name = `${mask.name}@${year}-${
now.getMonth() + 1
}-${now.getDate()}@${now.getHours()}:${now.getMinutes()}`;
}
}
}
const id = nanoid();
masks[id] = {
...createEmptyMask(),
Expand Down
38 changes: 22 additions & 16 deletions app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export function trimTopic(topic: string) {
// Fix an issue where double quotes still show in the Indonesian language
// This will remove the specified punctuation from the end of the string
// and also trim quotes from both the start and end if they exist.
return topic.replace(/^["“”]+|["“”]+$/g, "").replace(/[,。!?”“"、,.!?]*$/, "");
return topic
.replace(/^["“”]+|["“”]+$/g, "")
.replace(/[,。!?”“"、,.!?]*$/, "");
}

export async function copyToClipboard(text: string) {
Expand Down Expand Up @@ -40,8 +42,8 @@ export async function downloadAs(text: string, filename: string) {
defaultPath: `${filename}`,
filters: [
{
name: `${filename.split('.').pop()} files`,
extensions: [`${filename.split('.').pop()}`],
name: `${filename.split(".").pop()} files`,
extensions: [`${filename.split(".").pop()}`],
},
{
name: "All Files",
Expand All @@ -52,10 +54,14 @@ export async function downloadAs(text: string, filename: string) {

if (result !== null) {
try {
await window.__TAURI__.fs.writeBinaryFile(
result,
new Uint8Array([...text].map((c) => c.charCodeAt(0)))
);
// await window.__TAURI__.fs.writeBinaryFile(
// result,
// new Uint8Array([...text].map((c) => c.charCodeAt(0)))
// );
// 修复客户端导出json时的乱码现象
const encoder = new TextEncoder();
const data = encoder.encode(text);
await window.__TAURI__.fs.writeBinaryFile(result, new Uint8Array(data));
showToast(Locale.Download.Success);
} catch (error) {
showToast(Locale.Download.Failed);
Expand All @@ -69,15 +75,15 @@ export async function downloadAs(text: string, filename: string) {
"href",
"data:text/plain;charset=utf-8," + encodeURIComponent(text),
);
element.setAttribute("download", filename);
element.setAttribute("download", filename);

element.style.display = "none";
document.body.appendChild(element);
element.style.display = "none";
document.body.appendChild(element);

element.click();
element.click();

document.body.removeChild(element);
}
document.body.removeChild(element);
}
}
export function readFromFile() {
return new Promise<string>((res, rej) => {
Expand Down Expand Up @@ -212,8 +218,8 @@ export function getCSSVar(varName: string) {
export function isMacOS(): boolean {
if (typeof window !== "undefined") {
let userAgent = window.navigator.userAgent.toLocaleLowerCase();
const macintosh = /iphone|ipad|ipod|macintosh/.test(userAgent)
return !!macintosh
const macintosh = /iphone|ipad|ipod|macintosh/.test(userAgent);
return !!macintosh;
}
return false
return false;
}
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"updater": {
"active": true,
"endpoints": [
"https://github.com/Yidadaa/ChatGPT-Next-Web/releases/latest/download/latest.json"
"https://github.com/htmambo/ChatGPT-Next-Web/releases/latest/download/latest.json"
],
"dialog": false,
"windows": {
Expand Down
Loading