diff --git a/README.md b/README.md index 07455d00d82..33f6e85cbb0 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ Your openai api key. ### `CODE` (optional) -Access passsword, separated by comma. +Access password, separated by comma. ### `BASE_URL` (optional) @@ -257,6 +257,10 @@ If your proxy needs password, use: bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/scripts/setup.sh) ``` +## Synchronizing Chat Records (UpStash) + +| [简体中文](./docs/synchronise-chat-logs-cn.md) | [English](./docs/synchronise-chat-logs-en.md) | [Italiano](./docs/synchronise-chat-logs-es.md) | [日本語](./docs/synchronise-chat-logs-ja.md) | [한국어](./docs/synchronise-chat-logs-ko.md) + ## Documentation > Please go to the [docs][./docs] directory for more documentation instructions. @@ -309,6 +313,7 @@ If you want to add a new translation, read this [document](./docs/translation.md [@AnsonHyq](https://github.com/AnsonHyq) [@synwith](https://github.com/synwith) [@piksonGit](https://github.com/piksonGit) +[@ouyangzhiping](https://github.com/ouyangzhiping) ### Contributor diff --git a/README_CN.md b/README_CN.md index b31e8b367ee..671e74b097d 100644 --- a/README_CN.md +++ b/README_CN.md @@ -169,6 +169,7 @@ bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/s ⚠️ 注意:如果你安装过程中遇到了问题,请使用 docker 部署。 + ## 鸣谢 ### 捐赠者 @@ -185,3 +186,4 @@ bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/s ## 开源协议 [MIT](https://opensource.org/license/mit/) + diff --git a/README_KO.md b/README_KO.md index 519dd9d9bb5..c4000c3a229 100644 --- a/README_KO.md +++ b/README_KO.md @@ -169,6 +169,7 @@ bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/s ⚠️ 주의: 설치 중 문제가 발생한 경우, docker로 배포하세요. + ## 감사의 말 ### 기부자 @@ -185,3 +186,4 @@ bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/s ## 오픈소스 라이센스 [MIT](https://opensource.org/license/mit/) + diff --git a/app/components/auth.tsx b/app/components/auth.tsx index 9a5b0c655e6..b82d0e894c7 100644 --- a/app/components/auth.tsx +++ b/app/components/auth.tsx @@ -15,7 +15,8 @@ export function AuthPage() { const access = useAccessStore(); const goHome = () => navigate(Path.Home); - const resetAccessCode = () => access.updateCode(""); // Reset access code to empty string + const goChat = () => navigate(Path.Chat); + const resetAccessCode = () => { access.updateCode(""); access.updateToken(""); }; // Reset access code to empty string useEffect(() => { if (getClientConfig()?.isApp) { @@ -42,17 +43,34 @@ export function AuthPage() { access.updateCode(e.currentTarget.value); }} /> + {!access.hideUserApiKey ? ( + <> +
{Locale.Auth.SubTips}
+ { + access.updateToken(e.currentTarget.value); + }} + /> + + ) : null}
+ { + resetAccessCode(); + goHome(); + }} /> - { - resetAccessCode(); - goHome(); - }} />
); diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 4e6aedecc60..cca096eb874 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -1155,7 +1155,13 @@ function _Chat() { {isUser ? ( ) : ( - + <> + {["system"].includes(message.role) ? ( + + ) : ( + + )} + )} diff --git a/app/components/exporter.tsx b/app/components/exporter.tsx index 5b3e8a9a180..0a885d87463 100644 --- a/app/components/exporter.tsx +++ b/app/components/exporter.tsx @@ -433,25 +433,55 @@ export function ImagePreviewer(props: { const isMobile = useMobileScreen(); - const download = () => { + const download = async () => { showToast(Locale.Export.Image.Toast); const dom = previewRef.current; if (!dom) return; - toPng(dom) - .then((blob) => { - if (!blob) return; - - if (isMobile || getClientConfig()?.isApp) { - showImageModal(blob); + + const isApp = getClientConfig()?.isApp; + + try { + const blob = await toPng(dom); + if (!blob) return; + + if (isMobile || (isApp && window.__TAURI__)) { + if (isApp && window.__TAURI__) { + const result = await window.__TAURI__.dialog.save({ + defaultPath: `${props.topic}.png`, + filters: [ + { + name: "PNG Files", + extensions: ["png"], + }, + { + name: "All Files", + extensions: ["*"], + }, + ], + }); + + if (result !== null) { + const response = await fetch(blob); + const buffer = await response.arrayBuffer(); + const uint8Array = new Uint8Array(buffer); + await window.__TAURI__.fs.writeBinaryFile(result, uint8Array); + showToast(Locale.Download.Success); + } else { + showToast(Locale.Download.Failed); + } } else { - const link = document.createElement("a"); - link.download = `${props.topic}.png`; - link.href = blob; - link.click(); - refreshPreview(); + showImageModal(blob); } - }) - .catch((e) => console.log("[Export Image] ", e)); + } else { + const link = document.createElement("a"); + link.download = `${props.topic}.png`; + link.href = blob; + link.click(); + refreshPreview(); + } + } catch (error) { + showToast(Locale.Download.Failed); + } }; const refreshPreview = () => { diff --git a/app/components/home.tsx b/app/components/home.tsx index 07d5e88b373..811cbdf51cb 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -128,8 +128,7 @@ function Screen() { const isHome = location.pathname === Path.Home; const isAuth = location.pathname === Path.Auth; const isMobileScreen = useMobileScreen(); - const shouldTightBorder = - config.tightBorder && !isMobileScreen && !getClientConfig()?.isApp; + const shouldTightBorder = getClientConfig()?.isApp || (config.tightBorder && !isMobileScreen); useEffect(() => { loadAsyncGoogleFont(); diff --git a/app/components/mask.tsx b/app/components/mask.tsx index 1ee1c239a74..9fe1d485a6b 100644 --- a/app/components/mask.tsx +++ b/app/components/mask.tsx @@ -393,11 +393,13 @@ export function MaskPage() { const [searchText, setSearchText] = useState(""); const masks = searchText.length > 0 ? searchMasks : allMasks; - // simple search, will refactor later + // refactored already, now it accurate const onSearch = (text: string) => { setSearchText(text); if (text.length > 0) { - const result = allMasks.filter((m) => m.name.includes(text)); + const result = allMasks.filter((m) => + m.name.toLowerCase().includes(text.toLowerCase()) + ); setSearchMasks(result); } else { setSearchMasks(allMasks); diff --git a/app/components/settings.tsx b/app/components/settings.tsx index 8ed6b77383c..795469a9681 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -753,7 +753,7 @@ export function Settings() { title={`${config.fontSize ?? 14}px`} value={config.fontSize} min="12" - max="18" + max="40" step="1" onChange={(e) => updateConfig( diff --git a/app/constant.ts b/app/constant.ts index 9e23ed510e4..e03e00971cc 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -8,7 +8,7 @@ export const FETCH_COMMIT_URL = `https://api.github.com/repos/${OWNER}/${REPO}/c export const FETCH_TAG_URL = `https://api.github.com/repos/${OWNER}/${REPO}/tags?per_page=1`; export const RUNTIME_CONFIG_DOM = "danger-runtime-config"; -export const DEFAULT_CORS_HOST = "https://nb.nextweb.fun"; +export const DEFAULT_CORS_HOST = "https://ab.nextweb.fun"; export const DEFAULT_API_HOST = `${DEFAULT_CORS_HOST}/api/proxy`; export enum Path { diff --git a/app/global.d.ts b/app/global.d.ts index 524ce77dbc6..e0a2c3f0686 100644 --- a/app/global.d.ts +++ b/app/global.d.ts @@ -13,5 +13,17 @@ declare module "*.svg"; declare interface Window { __TAURI__?: { writeText(text: string): Promise; + invoke(command: string, payload?: Record): Promise; + dialog: { + save(options?: Record): Promise; + }; + fs: { + writeBinaryFile(path: string, data: Uint8Array): Promise; + }; + notification:{ + requestPermission(): Promise; + isPermissionGranted(): Promise; + sendNotification(options: string | Options): void; + }; }; } diff --git a/app/locales/ar.ts b/app/locales/ar.ts index 520cb26356e..d5844acd695 100644 --- a/app/locales/ar.ts +++ b/app/locales/ar.ts @@ -10,6 +10,7 @@ const ar: PartialLocaleType = { Auth: { Title: "تحتاج إلى رمز الوصول", Tips: "يرجى إدخال رمز الوصول أدناه", + SubTips: "أو أدخل مفتاح واجهة برمجة تطبيقات OpenAI الخاص بك", Input: "رمز الوصول", Confirm: "تأكيد", Later: "لاحقًا", diff --git a/app/locales/bn.ts b/app/locales/bn.ts index 2d2266b3f43..2db132cecc2 100644 --- a/app/locales/bn.ts +++ b/app/locales/bn.ts @@ -10,6 +10,7 @@ const bn: PartialLocaleType = { Auth: { Title: "একটি অ্যাক্সেস কোড প্রয়োজন", Tips: "নীচে অ্যাক্সেস কোড ইনপুট করুন", + SubTips: "অথবা আপনার OpenAI API কী প্রবেশ করুন", Input: "অ্যাক্সেস কোড", Confirm: "নিশ্চিত করুন", Later: "পরে", diff --git a/app/locales/cn.ts b/app/locales/cn.ts index b2afc753457..4cd963fb8e2 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -13,6 +13,7 @@ const cn = { Auth: { Title: "需要密码", Tips: "管理员开启了密码验证,请在下方填入访问码", + SubTips: "或者输入你的 OpenAI API 密钥", Input: "在此处填写访问码", Confirm: "确认", Later: "稍后再说", @@ -323,6 +324,10 @@ const cn = { Success: "已写入剪切板", Failed: "复制失败,请赋予剪切板权限", }, + Download: { + Success: "内容已下载到您的目录。", + Failed: "下载失败。", + }, Context: { Toast: (x: any) => `包含 ${x} 条预设提示词`, Edit: "当前对话设置", diff --git a/app/locales/en.ts b/app/locales/en.ts index 697d09d1f4e..928c4b72d4e 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -15,6 +15,7 @@ const en: LocaleType = { Auth: { Title: "Need Access Code", Tips: "Please enter access code below", + SubTips: "Or enter your OpenAI API Key", Input: "access code", Confirm: "Confirm", Later: "Later", @@ -329,6 +330,10 @@ const en: LocaleType = { Success: "Copied to clipboard", Failed: "Copy failed, please grant permission to access clipboard", }, + Download: { + Success: "Content downloaded to your directory.", + Failed: "Download failed.", + }, Context: { Toast: (x: any) => `With ${x} contextual prompts`, Edit: "Current Chat Settings", diff --git a/app/locales/id.ts b/app/locales/id.ts index 244c5ade19a..b5e4a70b751 100644 --- a/app/locales/id.ts +++ b/app/locales/id.ts @@ -4,12 +4,12 @@ import { PartialLocaleType } from "./index"; const id: PartialLocaleType = { WIP: "Coming Soon...", Error: { - Unauthorized: - "Akses tidak diizinkan. Silakan [otorisasi](/#/auth) dengan memasukkan kode akses.", - }, + Unauthorized: "Akses tidak diizinkan, silakan masukkan kode akses atau masukkan kunci API OpenAI Anda. di halaman [autentikasi](/#/auth) atau di halaman [Pengaturan](/#/settings).", + }, Auth: { Title: "Diperlukan Kode Akses", Tips: "Masukkan kode akses di bawah", + SubTips: "Atau masukkan kunci API OpenAI Anda", Input: "Kode Akses", Confirm: "Konfirmasi", Later: "Nanti", @@ -301,6 +301,10 @@ const id: PartialLocaleType = { Failed: "Gagal menyalin, mohon berikan izin untuk mengakses clipboard atau Clipboard API tidak didukung (Tauri)", }, + Download: { + Success: "Konten berhasil diunduh ke direktori Anda.", + Failed: "Unduhan gagal.", + }, Context: { Toast: (x: any) => `Dengan ${x} promp kontekstual`, Edit: "Pengaturan Obrolan Saat Ini", diff --git a/app/locales/tw.ts b/app/locales/tw.ts index 15f6648e659..e9f38d097e1 100644 --- a/app/locales/tw.ts +++ b/app/locales/tw.ts @@ -7,13 +7,13 @@ const tw: PartialLocaleType = { Unauthorized: "目前您的狀態是未授權,請前往[設定頁面](/#/auth)輸入授權碼。", }, ChatItem: { - ChatItemCount: (count: number) => `${count} 條對話`, + ChatItemCount: (count: number) => `${count} 則對話`, }, Chat: { - SubTitle: (count: number) => `您已經與 ChatGPT 進行了 ${count} 條對話`, + SubTitle: (count: number) => `您已經與 ChatGPT 進行了 ${count} 則對話`, Actions: { - ChatList: "查看訊息列表", - CompressedHistory: "查看壓縮後的歷史 Prompt", + ChatList: "檢視訊息列表", + CompressedHistory: "檢視壓縮後的歷史 Prompt", Export: "匯出聊天紀錄", Copy: "複製", Stop: "停止", @@ -23,15 +23,15 @@ const tw: PartialLocaleType = { Rename: "重新命名對話", Typing: "正在輸入…", Input: (submitKey: string) => { - var inputHints = `輸入訊息後,按下 ${submitKey} 鍵即可發送`; + var inputHints = `輸入訊息後,按下 ${submitKey} 鍵即可傳送`; if (submitKey === String(SubmitKey.Enter)) { inputHints += ",Shift + Enter 鍵換行"; } return inputHints; }, - Send: "發送", + Send: "傳送", Config: { - Reset: "重置預設", + Reset: "重設", SaveAs: "另存新檔", }, }, @@ -46,7 +46,7 @@ const tw: PartialLocaleType = { Title: "上下文記憶 Prompt", EmptyContent: "尚未記憶", Copy: "複製全部", - Send: "發送記憶", + Send: "傳送記憶", Reset: "重設對話", ResetConfirm: "重設後將清除目前對話記錄以及歷史記憶,確認重設?", }, @@ -71,22 +71,22 @@ const tw: PartialLocaleType = { }, InjectSystemPrompts: { Title: "匯入系統提示", - SubTitle: "強制在每個請求的訊息列表開頭添加一個模擬 ChatGPT 的系統提示", + SubTitle: "強制在每個請求的訊息列表開頭新增一個模擬 ChatGPT 的系統提示", }, Update: { - Version: (x: string) => `當前版本:${x}`, + Version: (x: string) => `目前版本:${x}`, IsLatest: "已是最新版本", CheckUpdate: "檢查更新", IsChecking: "正在檢查更新...", FoundUpdate: (x: string) => `發現新版本:${x}`, GoToUpdate: "前往更新", }, - SendKey: "發送鍵", + SendKey: "傳送鍵", Theme: "主題", TightBorder: "緊湊邊框", SendPreviewBubble: { Title: "預覽氣泡", - SubTitle: "在預覽氣泡中預覽 Markdown 内容", + SubTitle: "在預覽氣泡中預覽 Markdown 內容", }, Mask: { Splash: { @@ -101,7 +101,7 @@ const tw: PartialLocaleType = { }, List: "自定義提示詞列表", ListCount: (builtin: number, custom: number) => - `內建 ${builtin} 條,用戶定義 ${custom} 條`, + `內建 ${builtin} 條,使用者定義 ${custom} 條`, Edit: "編輯", Modal: { Title: "提示詞列表", @@ -132,7 +132,7 @@ const tw: PartialLocaleType = { }, IsChecking: "正在檢查…", Check: "重新檢查", - NoAccess: "輸入API Key查看餘額", + NoAccess: "輸入 API Key 檢視餘額", }, AccessCode: { Title: "授權碼", @@ -150,7 +150,7 @@ const tw: PartialLocaleType = { }, PresencePenalty: { Title: "話題新穎度 (presence_penalty)", - SubTitle: "值越大,越有可能擴展到新話題", + SubTitle: "值越大,越有可能拓展到新話題", }, FrequencyPenalty: { Title: "頻率懲罰度 (frequency_penalty)", @@ -163,7 +163,7 @@ const tw: PartialLocaleType = { Error: "出錯了,請稍後再嘗試", Prompt: { History: (content: string) => - "這是 AI 與用戶的歷史聊天總結,作為前情提要:" + content, + "這是 AI 與使用者的歷史聊天總結,作為前情提要:" + content, Topic: "Use the language used by the user (e.g. en for english conversation, zh-hant for chinese conversation, etc.) to generate a title (at most 6 words) summarizing our conversation without any lead-in, quotation marks, preamble like 'Title:', direct text copies, single-word replies, quotation marks, translations, or brackets. Remove enclosing quotation marks. The title should make third-party grasp the essence of the conversation in first sight.", Summarize: @@ -192,16 +192,16 @@ const tw: PartialLocaleType = { Item: { Info: (count: number) => `包含 ${count} 條預設對話`, Chat: "對話", - View: "查看", + View: "檢視", Edit: "編輯", - Delete: "删除", - DeleteConfirm: "確認删除?", + Delete: "刪除", + DeleteConfirm: "確認刪除?", }, EditModal: { Title: (readonly: boolean) => - `編輯預設面具 ${readonly ? "(只读)" : ""}`, + `編輯預設面具 ${readonly ? "(只讀)" : ""}`, Download: "下載預設", - Clone: "克隆預設", + Clone: "複製預設", }, Config: { Avatar: "角色頭像", @@ -215,7 +215,7 @@ const tw: PartialLocaleType = { SubTitle: "現在開始,與面具背後的靈魂思維碰撞", More: "搜尋更多", NotShow: "不再呈現", - ConfirmNoShow: "確認禁用?禁用後可以随時在設定中重新啟用。", + ConfirmNoShow: "確認停用?停用後可以隨時在設定中重新啟用。", }, UI: { Confirm: "確認", diff --git a/app/masks/en.ts b/app/masks/en.ts index 1ab40d59b03..ed130351f1e 100644 --- a/app/masks/en.ts +++ b/app/masks/en.ts @@ -35,7 +35,7 @@ export const EN_MASKS: BuiltinMask[] = [ id: "prompt-improve-0", role: "user", content: - 'Read all of the instructions below and once you understand them say "Shall we begin:"\n \nI want you to become my Prompt Creator. Your goal is to help me craft the best possible prompt for my needs. The prompt will be used by you, ChatGPT. You will follow the following process:\nYour first response will be to ask me what the prompt should be about. I will provide my answer, but we will need to improve it through continual iterations by going through the next steps.\n \nBased on my input, you will generate 3 sections.\n \nRevised Prompt (provide your rewritten prompt. it should be clear, concise, and easily understood by you)\nSuggestions (provide 3 suggestions on what details to include in the prompt to improve it)\nQuestions (ask the 3 most relevant questions pertaining to what additional information is needed from me to improve the prompt)\n \nAt the end of these sections give me a reminder of my options which are:\n \nOption 1: Read the output and provide more info or answer one or more of the questions\nOption 2: Type "Use this prompt" and I will submit this as a query for you\nOption 3: Type "Restart" to restart this process from the beginning\nOption 4: Type "Quit" to end this script and go back to a regular ChatGPT session\n \nIf I type "Option 2", "2" or "Use this prompt" then we have finsihed and you should use the Revised Prompt as a prompt to generate my request\nIf I type "option 3", "3" or "Restart" then forget the latest Revised Prompt and restart this process\nIf I type "Option 4", "4" or "Quit" then finish this process and revert back to your general mode of operation\n\n\nWe will continue this iterative process with me providing additional information to you and you updating the prompt in the Revised Prompt section until it is complete.', + 'Read all of the instructions below and once you understand them say "Shall we begin:"\n \nI want you to become my Prompt Creator. Your goal is to help me craft the best possible prompt for my needs. The prompt will be used by you, ChatGPT. You will follow the following process:\nYour first response will be to ask me what the prompt should be about. I will provide my answer, but we will need to improve it through continual iterations by going through the next steps.\n \nBased on my input, you will generate 3 sections.\n \nRevised Prompt (provide your rewritten prompt. it should be clear, concise, and easily understood by you)\nSuggestions (provide 3 suggestions on what details to include in the prompt to improve it)\nQuestions (ask the 3 most relevant questions pertaining to what additional information is needed from me to improve the prompt)\n \nAt the end of these sections give me a reminder of my options which are:\n \nOption 1: Read the output and provide more info or answer one or more of the questions\nOption 2: Type "Use this prompt" and I will submit this as a query for you\nOption 3: Type "Restart" to restart this process from the beginning\nOption 4: Type "Quit" to end this script and go back to a regular ChatGPT session\n \nIf I type "Option 2", "2" or "Use this prompt" then we have finished and you should use the Revised Prompt as a prompt to generate my request\nIf I type "option 3", "3" or "Restart" then forget the latest Revised Prompt and restart this process\nIf I type "Option 4", "4" or "Quit" then finish this process and revert back to your general mode of operation\n\n\nWe will continue this iterative process with me providing additional information to you and you updating the prompt in the Revised Prompt section until it is complete.', date: "", }, { diff --git a/app/store/chat.ts b/app/store/chat.ts index 269cc4a33c9..56ac8db6cc1 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -1,6 +1,3 @@ -import { create } from "zustand"; -import { persist } from "zustand/middleware"; - import { trimTopic } from "../utils"; import Locale, { getLang } from "../locales"; diff --git a/app/store/config.ts b/app/store/config.ts index 956e5f3eb81..184355c94a3 100644 --- a/app/store/config.ts +++ b/app/store/config.ts @@ -1,4 +1,5 @@ import { LLMModel } from "../client/api"; +import { isMacOS } from "../utils"; import { getClientConfig } from "../config/client"; import { DEFAULT_INPUT_TEMPLATE, @@ -27,7 +28,7 @@ export enum Theme { export const DEFAULT_CONFIG = { lastUpdate: Date.now(), // timestamp, to merge state - submitKey: SubmitKey.CtrlEnter as SubmitKey, + submitKey: isMacOS() ? SubmitKey.MetaEnter : SubmitKey.CtrlEnter, avatar: "1f603", fontSize: 14, theme: Theme.Auto as Theme, @@ -69,7 +70,7 @@ export function limitNumber( max: number, defaultValue: number, ) { - if (typeof x !== "number" || isNaN(x)) { + if (isNaN(x)) { return defaultValue; } @@ -132,9 +133,7 @@ export const useAppConfig = createPersistStore( .customModels.split(",") .filter((v) => !!v && v.length > 0) .map((m) => ({ name: m, available: true })); - - const models = get().models.concat(customModels); - return models; + return get().models.concat(customModels); }, }), { diff --git a/app/store/sync.ts b/app/store/sync.ts index c194162fcb0..b74f6895f6d 100644 --- a/app/store/sync.ts +++ b/app/store/sync.ts @@ -1,3 +1,4 @@ +import { getClientConfig } from "../config/client"; import { Updater } from "../typing"; import { ApiPath, STORAGE_KEY, StoreKey } from "../constant"; import { createPersistStore } from "../utils/store"; @@ -20,6 +21,7 @@ export interface WebDavConfig { password: string; } +const isApp = !!getClientConfig()?.isApp; export type SyncStore = GetStoreState; const DEFAULT_SYNC_STATE = { @@ -57,7 +59,11 @@ export const useSyncStore = createPersistStore( export() { const state = getLocalAppState(); - const fileName = `Backup-${new Date().toLocaleString()}.json`; + const datePart = isApp + ? `${new Date().toLocaleDateString().replace(/\//g, '_')} ${new Date().toLocaleTimeString().replace(/:/g, '_')}` + : new Date().toLocaleString(); + + const fileName = `Backup-${datePart}.json`; downloadAs(JSON.stringify(state), fileName); }, @@ -95,7 +101,7 @@ export const useSyncStore = createPersistStore( mergeAppState(localState, remoteState); setLocalAppState(localState); } catch (e) { - console.log("[Sync] failed to get remoate state", e); + console.log("[Sync] failed to get remote state", e); } await client.set(config.username, JSON.stringify(localState)); diff --git a/app/store/update.ts b/app/store/update.ts index 42b86586c62..2b088a13d7a 100644 --- a/app/store/update.ts +++ b/app/store/update.ts @@ -2,8 +2,11 @@ import { FETCH_COMMIT_URL, FETCH_TAG_URL, StoreKey } from "../constant"; import { api } from "../client/api"; import { getClientConfig } from "../config/client"; import { createPersistStore } from "../utils/store"; +import ChatGptIcon from "../icons/chatgpt.png"; +import Locale from "../locales"; const ONE_MINUTE = 60 * 1000; +const isApp = !!getClientConfig()?.isApp; function formatVersionDate(t: string) { const d = new Date(+t); @@ -80,6 +83,38 @@ export const useUpdateStore = createPersistStore( set(() => ({ remoteVersion: remoteId, })); + if (window.__TAURI__?.notification && isApp) { + // Check if notification permission is granted + await window.__TAURI__?.notification.isPermissionGranted().then((granted) => { + if (!granted) { + return; + } else { + // Request permission to show notifications + window.__TAURI__?.notification.requestPermission().then((permission) => { + if (permission === 'granted') { + if (version === remoteId) { + // Show a notification using Tauri + window.__TAURI__?.notification.sendNotification({ + title: "ChatGPT Next Web", + body: `${Locale.Settings.Update.IsLatest}`, + icon: `${ChatGptIcon.src}`, + sound: "Default" + }); + } else { + const updateMessage = Locale.Settings.Update.FoundUpdate(`${remoteId}`); + // Show a notification for the new version using Tauri + window.__TAURI__?.notification.sendNotification({ + title: "ChatGPT Next Web", + body: updateMessage, + icon: `${ChatGptIcon.src}`, + sound: "Default" + }); + } + } + }); + } + }); + } console.log("[Got Upstream] ", remoteId); } catch (error) { console.error("[Fetch Upstream Commit Id]", error); diff --git a/app/utils.ts b/app/utils.ts index 37c17dd760d..acc140ac30b 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -31,12 +31,41 @@ export async function copyToClipboard(text: string) { } } -export function downloadAs(text: string, filename: string) { - const element = document.createElement("a"); - element.setAttribute( - "href", - "data:text/plain;charset=utf-8," + encodeURIComponent(text), - ); +export async function downloadAs(text: string, filename: string) { + if (window.__TAURI__) { + const result = await window.__TAURI__.dialog.save({ + defaultPath: `${filename}`, + filters: [ + { + name: `${filename.split('.').pop()} files`, + extensions: [`${filename.split('.').pop()}`], + }, + { + name: "All Files", + extensions: ["*"], + }, + ], + }); + + if (result !== null) { + try { + await window.__TAURI__.fs.writeBinaryFile( + result, + new Uint8Array([...text].map((c) => c.charCodeAt(0))) + ); + showToast(Locale.Download.Success); + } catch (error) { + showToast(Locale.Download.Failed); + } + } else { + showToast(Locale.Download.Failed); + } + } else { + const element = document.createElement("a"); + element.setAttribute( + "href", + "data:text/plain;charset=utf-8," + encodeURIComponent(text), + ); element.setAttribute("download", filename); element.style.display = "none"; @@ -46,7 +75,7 @@ export function downloadAs(text: string, filename: string) { document.body.removeChild(element); } - +} export function readFromFile() { return new Promise((res, rej) => { const fileInput = document.createElement("input"); @@ -173,3 +202,15 @@ export function autoGrowTextArea(dom: HTMLTextAreaElement) { export function getCSSVar(varName: string) { return getComputedStyle(document.body).getPropertyValue(varName).trim(); } + +/** + * Detects Macintosh + */ +export function isMacOS(): boolean { + if (typeof window !== "undefined") { + let userAgent = window.navigator.userAgent.toLocaleLowerCase(); + const macintosh = /iphone|ipad|ipod|macintosh/.test(userAgent) + return !!macintosh + } + return false +} diff --git a/docs/images/upstash-1.png b/docs/images/upstash-1.png new file mode 100644 index 00000000000..5813c521f3c Binary files /dev/null and b/docs/images/upstash-1.png differ diff --git a/docs/images/upstash-2.png b/docs/images/upstash-2.png new file mode 100644 index 00000000000..91078642d3b Binary files /dev/null and b/docs/images/upstash-2.png differ diff --git a/docs/images/upstash-3.png b/docs/images/upstash-3.png new file mode 100644 index 00000000000..06c53d190e1 Binary files /dev/null and b/docs/images/upstash-3.png differ diff --git a/docs/images/upstash-4.png b/docs/images/upstash-4.png new file mode 100644 index 00000000000..ae301c4d349 Binary files /dev/null and b/docs/images/upstash-4.png differ diff --git a/docs/images/upstash-5.png b/docs/images/upstash-5.png new file mode 100644 index 00000000000..728a374600f Binary files /dev/null and b/docs/images/upstash-5.png differ diff --git a/docs/images/upstash-6.png b/docs/images/upstash-6.png new file mode 100644 index 00000000000..0991c89cf80 Binary files /dev/null and b/docs/images/upstash-6.png differ diff --git a/docs/images/upstash-7.png b/docs/images/upstash-7.png new file mode 100644 index 00000000000..3b3408537ad Binary files /dev/null and b/docs/images/upstash-7.png differ diff --git a/docs/synchronise-chat-logs-cn.md b/docs/synchronise-chat-logs-cn.md new file mode 100644 index 00000000000..59f2774292e --- /dev/null +++ b/docs/synchronise-chat-logs-cn.md @@ -0,0 +1,31 @@ +# 同步聊天记录 +## 准备工作 +- GitHub账号 +- 拥有自己搭建过的ChatGPT-Next-Web的服务器 +- [UpStash](https://upstash.com) + +## 开始教程 +1. 注册UpStash账号 +2. 创建数据库 + + ![注册登录](./images/upstash-1.png) + + ![创建数据库](./images/upstash-2.png) + + ![选择服务器](./images/upstash-3.png) + +3. 找到REST API,分别复制UPSTASH_REDIS_REST_URL和UPSTASH_REDIS_REST_TOKEN(⚠切记⚠:不要泄露Token!) + + ![复制](./images/upstash-4.png) + +4. UPSTASH_REDIS_REST_URL和UPSTASH_REDIS_REST_TOKEN复制到你的同步配置,点击**检查可用性** + + ![同步1](./images/upstash-5.png) + + 如果没什么问题,那就成功了 + + ![同步可用性完成的样子](./images/upstash-6.png) + +5. Success! + + ![好耶~!](./images/upstash-7.png) diff --git a/docs/synchronise-chat-logs-en.md b/docs/synchronise-chat-logs-en.md new file mode 100644 index 00000000000..04d05607175 --- /dev/null +++ b/docs/synchronise-chat-logs-en.md @@ -0,0 +1,31 @@ +# Synchronize Chat Logs with UpStash +## Prerequisites +- GitHub account +- Your own ChatGPT-Next-Web server set up +- [UpStash](https://upstash.com) + +## Getting Started +1. Register for an UpStash account. +2. Create a database. + + ![Register and Login](./images/upstash-1.png) + + ![Create Database](./images/upstash-2.png) + + ![Select Server](./images/upstash-3.png) + +3. Find the REST API and copy UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN (⚠Important⚠: Do not share your token!) + + ![Copy](./images/upstash-4.png) + +4. Copy UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN into your synchronization configuration, then click **Check Availability**. + + ![Synchronize 1](./images/upstash-5.png) + + If everything is in order, you've successfully completed this step. + + ![Sync Availability Check Completed](./images/upstash-6.png) + +5. Success! + + ![Great job~!](./images/upstash-7.png) \ No newline at end of file diff --git a/docs/synchronise-chat-logs-es.md b/docs/synchronise-chat-logs-es.md new file mode 100644 index 00000000000..40135f1f620 --- /dev/null +++ b/docs/synchronise-chat-logs-es.md @@ -0,0 +1,31 @@ +# Sincronizzare i Log delle Chat con UpStash +## Prerequisiti +- Account GitHub +- Server ChatGPT-Next-Web di propria configurazione +- [UpStash](https://upstash.com) + +## Per iniziare +1. Registrarsi per un account UpStash. +2. Creare un database. + + ![Registrarsi ed Accedere](./images/upstash-1.png) + + ![Creare un Database](./images/upstash-2.png) + + ![Selezionare il Server](./images/upstash-3.png) + +3. Trovare l'API REST e copiare UPSTASH_REDIS_REST_URL e UPSTASH_REDIS_REST_TOKEN (⚠Importante⚠: Non condividere il token!) + + ![Copia](./images/upstash-4.png) + +4. Copiare UPSTASH_REDIS_REST_URL e UPSTASH_REDIS_REST_TOKEN nella configurazione di sincronizzazione, quindi fare clic su **Verifica la Disponibilità**. + + ![Sincronizzazione 1](./images/upstash-5.png) + + Se tutto è in ordine, hai completato con successo questa fase. + + ![Verifica la Disponibilità della Sincronizzazione Completata](./images/upstash-6.png) + +5. Successo! + + ![Ottimo lavoro~!](./images/upstash-7.png) \ No newline at end of file diff --git a/docs/synchronise-chat-logs-ja.md b/docs/synchronise-chat-logs-ja.md new file mode 100644 index 00000000000..ba75110fe68 --- /dev/null +++ b/docs/synchronise-chat-logs-ja.md @@ -0,0 +1,31 @@ +# UpStashを使用してチャットログを同期する +## 事前準備 +- GitHubアカウント +- 自分自身でChatGPT-Next-Webのサーバーをセットアップしていること +- [UpStash](https://upstash.com) + +## 始める +1. UpStashアカウントを登録します。 +2. データベースを作成します。 + + ![登録とログイン](./images/upstash-1.png) + + ![データベースの作成](./images/upstash-2.png) + + ![サーバーの選択](./images/upstash-3.png) + +3. REST APIを見つけ、UPSTASH_REDIS_REST_URLとUPSTASH_REDIS_REST_TOKENをコピーします(⚠重要⚠:トークンを共有しないでください!) + + ![コピー](./images/upstash-4.png) + +4. UPSTASH_REDIS_REST_URLとUPSTASH_REDIS_REST_TOKENを同期設定にコピーし、次に「可用性を確認」をクリックします。 + + ![同期1](./images/upstash-5.png) + + すべてが正常であれば、このステップは成功です。 + + ![同期可用性チェックが完了しました](./images/upstash-6.png) + +5. 成功! + + ![お疲れ様でした~!](./images/upstash-7.png) \ No newline at end of file diff --git a/docs/synchronise-chat-logs-ko.md b/docs/synchronise-chat-logs-ko.md new file mode 100644 index 00000000000..88e6e2dda69 --- /dev/null +++ b/docs/synchronise-chat-logs-ko.md @@ -0,0 +1,31 @@ +# UpStash를 사용하여 채팅 기록 동기화 +## 사전 준비물 +- GitHub 계정 +- 자체 ChatGPT-Next-Web 서버 설정 +- [UpStash](https://upstash.com) + +## 시작하기 +1. UpStash 계정 등록 +2. 데이터베이스 생성 + + ![등록 및 로그인](./images/upstash-1.png) + + ![데이터베이스 생성](./images/upstash-2.png) + + ![서버 선택](./images/upstash-3.png) + +3. REST API를 찾아 UPSTASH_REDIS_REST_URL 및 UPSTASH_REDIS_REST_TOKEN을 복사합니다 (⚠주의⚠: 토큰을 공유하지 마십시오!) + + ![복사](./images/upstash-4.png) + +4. UPSTASH_REDIS_REST_URL 및 UPSTASH_REDIS_REST_TOKEN을 동기화 구성에 복사한 다음 **가용성 확인**을 클릭합니다. + + ![동기화 1](./images/upstash-5.png) + + 모든 것이 정상인 경우,이 단계를 성공적으로 완료했습니다. + + ![동기화 가용성 확인 완료](./images/upstash-6.png) + +5. 성공! + + ![잘 했어요~!](./images/upstash-7.png) \ No newline at end of file diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index ac5d04e836e..fee1c860fb9 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -17,7 +17,7 @@ tauri-build = { version = "1.3.0", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.3.0", features = ["clipboard-all", "dialog-all", "shell-open", "updater", "window-close", "window-hide", "window-maximize", "window-minimize", "window-set-icon", "window-set-ignore-cursor-events", "window-set-resizable", "window-show", "window-start-dragging", "window-unmaximize", "window-unminimize"] } +tauri = { version = "1.3.0", features = ["notification-all", "fs-all", "clipboard-all", "dialog-all", "shell-open", "updater", "window-close", "window-hide", "window-maximize", "window-minimize", "window-set-icon", "window-set-ignore-cursor-events", "window-set-resizable", "window-show", "window-start-dragging", "window-unmaximize", "window-unminimize"] } tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } [features] diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 77b02a3bae8..e530203f680 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -9,7 +9,7 @@ }, "package": { "productName": "ChatGPT Next Web", - "version": "2.9.7" + "version": "2.9.9" }, "tauri": { "allowlist": { @@ -44,6 +44,12 @@ "startDragging": true, "unmaximize": true, "unminimize": true + }, + "fs": { + "all": true + }, + "notification": { + "all": true } }, "bundle": {