This commit is contained in:
GH Action - Upstream Sync 2023-08-16 01:03:31 +00:00
commit 78d2974a31
5 changed files with 74 additions and 20 deletions

View File

@ -7,6 +7,8 @@ import { useAccessStore } from "../store";
import Locale from "../locales"; import Locale from "../locales";
import BotIcon from "../icons/bot.svg"; import BotIcon from "../icons/bot.svg";
import { useEffect } from "react";
import { getClientConfig } from "../config/client";
export function AuthPage() { export function AuthPage() {
const navigate = useNavigate(); const navigate = useNavigate();
@ -14,6 +16,13 @@ export function AuthPage() {
const goHome = () => navigate(Path.Home); const goHome = () => navigate(Path.Home);
useEffect(() => {
if (getClientConfig()?.isApp) {
navigate(Path.Settings);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return ( return (
<div className={styles["auth-page"]}> <div className={styles["auth-page"]}>
<div className={`no-dark ${styles["auth-logo"]}`}> <div className={`no-dark ${styles["auth-logo"]}`}>

View File

@ -1123,9 +1123,9 @@ function _Chat() {
10, 10,
); );
chatStore.updateCurrentSession((session) => { chatStore.updateCurrentSession((session) => {
const m = session.messages.find( const m = session.mask.context
(m) => m.id === message.id, .concat(session.messages)
); .find((m) => m.id === message.id);
if (m) { if (m) {
m.content = newMessage; m.content = newMessage;
} }

View File

@ -127,7 +127,7 @@ export function MessageExporter() {
]; ];
const { currentStep, setCurrentStepIndex, currentStepIndex } = const { currentStep, setCurrentStepIndex, currentStepIndex } =
useSteps(steps); useSteps(steps);
const formats = ["text", "image"] as const; const formats = ["text", "image", "json"] as const;
type ExportFormat = (typeof formats)[number]; type ExportFormat = (typeof formats)[number];
const [exportConfig, setExportConfig] = useState({ const [exportConfig, setExportConfig] = useState({
@ -157,7 +157,21 @@ export function MessageExporter() {
session.mask.context, session.mask.context,
selection, selection,
]); ]);
function preview() {
if (exportConfig.format === "text") {
return (
<MarkdownPreviewer messages={selectedMessages} topic={session.topic} />
);
} else if (exportConfig.format === "json") {
return (
<JsonPreviewer messages={selectedMessages} topic={session.topic} />
);
} else {
return (
<ImagePreviewer messages={selectedMessages} topic={session.topic} />
);
}
}
return ( return (
<> <>
<Steps <Steps
@ -212,16 +226,7 @@ export function MessageExporter() {
/> />
</div> </div>
{currentStep.value === "preview" && ( {currentStep.value === "preview" && (
<div className={styles["message-exporter-body"]}> <div className={styles["message-exporter-body"]}>{preview()}</div>
{exportConfig.format === "text" ? (
<MarkdownPreviewer
messages={selectedMessages}
topic={session.topic}
/>
) : (
<ImagePreviewer messages={selectedMessages} topic={session.topic} />
)}
</div>
)} )}
</> </>
); );
@ -545,12 +550,44 @@ export function MarkdownPreviewer(props: {
const download = () => { const download = () => {
downloadAs(mdText, `${props.topic}.md`); downloadAs(mdText, `${props.topic}.md`);
}; };
return ( return (
<> <>
<PreviewActions <PreviewActions
copy={copy} copy={copy}
download={download} download={download}
showCopy={true}
messages={props.messages}
/>
<div className="markdown-body">
<pre className={styles["export-content"]}>{mdText}</pre>
</div>
</>
);
}
export function JsonPreviewer(props: {
messages: ChatMessage[];
topic: string;
}) {
const msgs = props.messages.map((m) => ({
role: m.role,
content: m.content,
}));
const mdText = "\n" + JSON.stringify(msgs, null, 2) + "\n";
const copy = () => {
copyToClipboard(JSON.stringify(msgs, null, 2));
};
const download = () => {
downloadAs(JSON.stringify(msgs, null, 2), `${props.topic}.json`);
};
return (
<>
<PreviewActions
copy={copy}
download={download}
showCopy={true}
messages={props.messages} messages={props.messages}
/> />
<div className="markdown-body"> <div className="markdown-body">

View File

@ -1,10 +1,14 @@
import { getClientConfig } from "../config/client";
import { SubmitKey } from "../store/config"; import { SubmitKey } from "../store/config";
const isApp = !!getClientConfig()?.isApp;
const cn = { const cn = {
WIP: "该功能仍在开发中……", WIP: "该功能仍在开发中……",
Error: { Error: {
Unauthorized: Unauthorized: isApp
"访问密码不正确或为空,请前往[登录](/#/auth)页输入正确的访问密码,或者在[设置](/#/settings)页填入你自己的 OpenAI API Key。", ? "检测到无效 API Key请前往[设置](/#/settings)页检查 API Key 是否配置正确。"
: "访问密码不正确或为空,请前往[登录](/#/auth)页输入正确的访问密码,或者在[设置](/#/settings)页填入你自己的 OpenAI API Key。",
}, },
Auth: { Auth: {
Title: "需要密码", Title: "需要密码",

View File

@ -1,12 +1,16 @@
import { getClientConfig } from "../config/client";
import { SubmitKey } from "../store/config"; import { SubmitKey } from "../store/config";
import { LocaleType } from "./index"; import { LocaleType } from "./index";
// if you are adding a new translation, please use PartialLocaleType instead of LocaleType // if you are adding a new translation, please use PartialLocaleType instead of LocaleType
const isApp = !!getClientConfig()?.isApp;
const en: LocaleType = { const en: LocaleType = {
WIP: "Coming Soon...", WIP: "Coming Soon...",
Error: { Error: {
Unauthorized: Unauthorized: isApp
"Unauthorized access, please enter access code in [auth](/#/auth) page.", ? "Invalid API Key, please check it in [Settings](/#/settings) page."
: "Unauthorized access, please enter access code in [auth](/#/auth) page, or enter your OpenAI API Key.",
}, },
Auth: { Auth: {
Title: "Need Access Code", Title: "Need Access Code",