forked from XiaoMo/ChatGPT-Next-Web
Merge pull request #2636 from wangwentong-lunaon/main
This commit is contained in:
commit
ffddb7fb2b
@ -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">
|
||||||
|
Loading…
Reference in New Issue
Block a user