From e5f6133127894b68498de0a4d38741bccdba68f1 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Thu, 20 Jul 2023 23:17:58 +0800 Subject: [PATCH] feat: close #2447 pre-fill key/code/url --- app/command.ts | 2 ++ app/components/chat.tsx | 35 +++++++++++++++++++++++++++++++++++ app/locales/cn.ts | 5 +++++ app/locales/en.ts | 5 +++++ 4 files changed, 47 insertions(+) diff --git a/app/command.ts b/app/command.ts index 9330d4ff..e515e5f0 100644 --- a/app/command.ts +++ b/app/command.ts @@ -7,6 +7,8 @@ interface Commands { fill?: Command; submit?: Command; mask?: Command; + code?: Command; + settings?: Command; } export function useCommand(commands: Commands = {}) { diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 5084c568..db9f8448 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -882,6 +882,41 @@ export function Chat() { submit: (text) => { doSubmit(text); }, + code: (text) => { + console.log("[Command] got code from url: ", text); + showConfirm(Locale.URLCommand.Code + `code = ${text}`).then((res) => { + if (res) { + accessStore.updateCode(text); + } + }); + }, + settings: (text) => { + try { + const payload = JSON.parse(text) as { + key?: string; + url?: string; + }; + + console.log("[Command] got settings from url: ", payload); + + if (payload.key || payload.url) { + showConfirm( + Locale.URLCommand.Settings + + `\n${JSON.stringify(payload, null, 4)}`, + ).then((res) => { + if (!res) return; + if (payload.key) { + accessStore.updateToken(payload.key); + } + if (payload.url) { + accessStore.updateOpenAiUrl(payload.url); + } + }); + } + } catch { + console.error("[Command] failed to get settings from url: ", text); + } + }, }); return ( diff --git a/app/locales/cn.ts b/app/locales/cn.ts index e60e468a..54225e31 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -326,6 +326,11 @@ const cn = { More: "查看全部", }, + URLCommand: { + Code: "检测到链接中已经包含访问码,是否自动填入?", + Settings: "检测到链接中包含了预制设置,是否自动填入?", + }, + UI: { Confirm: "确认", Cancel: "取消", diff --git a/app/locales/en.ts b/app/locales/en.ts index 2a8c026f..ebc19f07 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -344,6 +344,11 @@ const en: LocaleType = { Topic: "Topic", Time: "Time", }, + + URLCommand: { + Code: "Detected access code from url, confirm to apply? ", + Settings: "Detected settings from url, confirm to apply?", + }, }; export default en;