From 082bd7e528a7ce1941da49f196a3ce28e2fd52c6 Mon Sep 17 00:00:00 2001 From: hoping Date: Thu, 25 Jan 2024 21:44:01 +0800 Subject: [PATCH 1/4] =?UTF-8?q?1=E3=80=81=E5=AF=BC=E5=85=A5=E9=9D=A2?= =?UTF-8?q?=E5=85=B7=E6=97=B6=E6=A3=80=E6=9F=A5=E6=8E=92=E9=99=A4=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E9=A1=B9=EF=BC=9B=202=E3=80=81=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E5=AF=BC=E5=87=BA=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=97=B6=E7=9A=84json=E4=B9=B1=E7=A0=81=E7=8E=B0=E8=B1=A1?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- README_CN.md | 2 +- app/store/mask.ts | 8 ++++++++ app/utils.ts | 12 ++++++++---- src-tauri/tauri.conf.json | 2 +- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3ac537abca8..546171ca65b 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/README_CN.md b/README_CN.md index 4acefefa518..96ee2cd2d47 100644 --- a/README_CN.md +++ b/README_CN.md @@ -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 在某些区域被污染了,绑定自定义域名即可直连。 diff --git a/app/store/mask.ts b/app/store/mask.ts index dfd4089b757..aed48fc8ee3 100644 --- a/app/store/mask.ts +++ b/app/store/mask.ts @@ -45,6 +45,14 @@ export const useMaskStore = createPersistStore( (set, get) => ({ create(mask?: Partial) { const masks = get().masks; + // 检查要导入的项目是否重复 + for (let existingMask of Object.values(masks)) { + if (existingMask.name === mask?.name && + JSON.stringify(existingMask.context) === JSON.stringify(mask?.context)) { + console.log("A mask with the same name and context already exists."); + return; + } + } const id = nanoid(); masks[id] = { ...createEmptyMask(), diff --git a/app/utils.ts b/app/utils.ts index ac7e80e7afd..f83d06d1958 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -52,10 +52,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); diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 75d6a0d0afa..bc5ba0e1139 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -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": { From 4cc130975df5a5728b2781dd12c341fa9125e678 Mon Sep 17 00:00:00 2001 From: hoping Date: Thu, 25 Jan 2024 22:01:09 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8E=BB=E9=87=8D?= =?UTF-8?q?=E5=90=8E=E7=9A=84=E8=BF=94=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/store/mask.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/store/mask.ts b/app/store/mask.ts index aed48fc8ee3..e13afe665d0 100644 --- a/app/store/mask.ts +++ b/app/store/mask.ts @@ -50,7 +50,7 @@ export const useMaskStore = createPersistStore( if (existingMask.name === mask?.name && JSON.stringify(existingMask.context) === JSON.stringify(mask?.context)) { console.log("A mask with the same name and context already exists."); - return; + return mask; } } const id = nanoid(); From eb6fedaef86823cc404457b990da806d0b953181 Mon Sep 17 00:00:00 2001 From: hoping <14806317+htmambo@users.noreply.github.com> Date: Thu, 25 Jan 2024 23:17:24 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=8E=BB=E9=87=8D=E5=90=8E=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=8E=B0=E6=9C=89=E7=9A=84=E9=9D=A2=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/store/mask.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/store/mask.ts b/app/store/mask.ts index e13afe665d0..36349284b52 100644 --- a/app/store/mask.ts +++ b/app/store/mask.ts @@ -50,7 +50,7 @@ export const useMaskStore = createPersistStore( if (existingMask.name === mask?.name && JSON.stringify(existingMask.context) === JSON.stringify(mask?.context)) { console.log("A mask with the same name and context already exists."); - return mask; + return existingMask; } } const id = nanoid(); From eed402a0357f463a0510c80ab1114cddc64c4fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=9C=E5=86=9C?= Date: Fri, 26 Jan 2024 15:26:15 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=201=E3=80=81=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E5=AF=BC=E5=87=BA=E6=96=87=E4=BB=B6=E4=B9=B1?= =?UTF-8?q?=E7=A0=81=EF=BC=9B=202=E3=80=81=E5=AF=BC=E5=85=A5=E6=97=B6?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E7=9A=84=E9=9D=A2=E5=85=B7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/store/mask.ts | 21 +++++++++++++++++++++ app/utils.ts | 38 ++++++++++++++++++++++---------------- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/app/store/mask.ts b/app/store/mask.ts index dfd4089b757..4befeeef556 100644 --- a/app/store/mask.ts +++ b/app/store/mask.ts @@ -45,6 +45,27 @@ export const useMaskStore = createPersistStore( (set, get) => ({ create(mask?: Partial) { 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(), diff --git a/app/utils.ts b/app/utils.ts index ac7e80e7afd..e41dfa1fddd 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -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) { @@ -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", @@ -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); @@ -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((res, rej) => { @@ -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; }