Fixed Bug 78519 - Special characters are used in the chat save to file dialog

This commit is contained in:
Timofey
2025-11-21 15:19:44 +08:00
parent 3b82226acc
commit 2fa5571d81
2 changed files with 7 additions and 3 deletions

View File

@ -39,12 +39,16 @@ export const convertMessagesToMd = (messages: ThreadMessageLike[]) => {
return content;
};
export const removeSpecialCharacter = (str: string) => {
return str.replace(/[\\/:*"<>|?]/g, "");
};
export const getMessageTitleFromMd = (md: string) => {
const lines = md.split("\n");
const title = lines[0].replace("## ", "");
return title.substring(0, 30);
return removeSpecialCharacter(title).substring(0, 30);
};
export const isDocument = (type: number) => {

View File

@ -9,7 +9,7 @@ import {
} from "@/database/threads";
import { readMessages } from "@/database/messages";
import type { Thread } from "@/lib/types";
import { convertMessagesToMd } from "@/lib/utils";
import { convertMessagesToMd, removeSpecialCharacter } from "@/lib/utils";
type UseThreadsStoreProps = {
threadId: string;
@ -71,7 +71,7 @@ const useThreadsStore = create<UseThreadsStoreProps>((set, get) => ({
const thread = thisStore.threads.find((t) => t.threadId === id);
const messages = await readMessages(id);
const title = thread?.title || "Chat Export";
const title = removeSpecialCharacter(thread?.title || "Chat Export");
const content = convertMessagesToMd(messages);