feat: 话题分享功能 #103
This commit is contained in:
parent
58817ae82f
commit
71ef0f319f
@ -79,6 +79,7 @@
|
||||
"topics.list": "Topic List",
|
||||
"topics.export.title": "Export",
|
||||
"topics.export.image": "Export as image",
|
||||
"topics.export.md": "Export as markdown",
|
||||
"input.new_topic": "New Topic",
|
||||
"input.topics": " Topics ",
|
||||
"input.clear": "Clear",
|
||||
@ -234,7 +235,7 @@
|
||||
"general.view_webdav_settings": "View WebDAV settings",
|
||||
"general.reset.title": "Data Reset",
|
||||
"general.reset.button": "Reset",
|
||||
"general.manually_check_update.title": "Manually Check for updates",
|
||||
"general.manually_check_update.title": "Turn off update checking",
|
||||
"data.webdav.title": "WebDAV",
|
||||
"data.webdav.host": "WebDAV Host",
|
||||
"data.webdav.host.placeholder": "http://localhost:8080",
|
||||
|
||||
@ -79,6 +79,7 @@
|
||||
"topics.list": "话题列表",
|
||||
"topics.export.title": "导出",
|
||||
"topics.export.image": "导出为图片",
|
||||
"topics.export.md": "导出为 Markdown",
|
||||
"input.new_topic": "新话题",
|
||||
"input.topics": " 话题 ",
|
||||
"input.clear": "清空消息",
|
||||
@ -234,7 +235,7 @@
|
||||
"general.reset.title": "重置数据",
|
||||
"general.reset.button": "重置",
|
||||
"general.view_webdav_settings": "查看 WebDAV 设置",
|
||||
"general.manually_check_update.title": "手动检查更新",
|
||||
"general.manually_check_update.title": "关闭更新检测",
|
||||
"data.webdav.title": "WebDAV",
|
||||
"data.webdav.host": "WebDAV 地址",
|
||||
"data.webdav.host.placeholder": "http://localhost:8080",
|
||||
|
||||
@ -79,6 +79,7 @@
|
||||
"topics.list": "話題列表",
|
||||
"topics.export.title": "匯出",
|
||||
"topics.export.image": "匯出為圖片",
|
||||
"topics.export.md": "匯出為 Markdown",
|
||||
"input.new_topic": "新話題",
|
||||
"input.topics": " 話題 ",
|
||||
"input.clear": "清除",
|
||||
@ -234,7 +235,7 @@
|
||||
"general.view_webdav_settings": "查看 WebDAV 設定",
|
||||
"general.reset.title": "資料重置",
|
||||
"general.reset.button": "重置",
|
||||
"general.manually_check_update.title": "手動檢查更新",
|
||||
"general.manually_check_update.title": "關閉更新檢查",
|
||||
"data.webdav.title": "WebDAV",
|
||||
"data.webdav.host": "WebDAV 主機位址",
|
||||
"data.webdav.host.placeholder": "http://localhost:8080",
|
||||
|
||||
@ -16,6 +16,7 @@ import { EVENT_NAMES, EventEmitter } from '@renderer/services/event'
|
||||
import store, { useAppSelector } from '@renderer/store'
|
||||
import { setGenerating } from '@renderer/store/runtime'
|
||||
import { Assistant, Topic } from '@renderer/types'
|
||||
import { exportTopicAsMarkdown } from '@renderer/utils/export'
|
||||
import { Dropdown, MenuProps } from 'antd'
|
||||
import dayjs from 'dayjs'
|
||||
import { findIndex } from 'lodash'
|
||||
@ -134,6 +135,11 @@ const Topics: FC<Props> = ({ assistant: _assistant, activeTopic, setActiveTopic
|
||||
label: t('chat.topics.export.image'),
|
||||
key: 'image',
|
||||
onClick: () => EventEmitter.emit(EVENT_NAMES.EXPORT_TOPIC_IMAGE, topic)
|
||||
},
|
||||
{
|
||||
label: t('chat.topics.export.md'),
|
||||
key: 'markdown',
|
||||
onClick: () => exportTopicAsMarkdown(topic)
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
24
src/renderer/src/utils/export.ts
Normal file
24
src/renderer/src/utils/export.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import db from '@renderer/databases'
|
||||
import { Message, Topic } from '@renderer/types'
|
||||
|
||||
export const exportMessageAsMarkdown = (message: Message) => {
|
||||
if (message.role === 'user') {
|
||||
return `### User\n\n${message.content}`
|
||||
}
|
||||
|
||||
return `### Assistant\n\n${message.content}`
|
||||
}
|
||||
|
||||
export const exportMessagesAsMarkdown = (messages: Message[]) => {
|
||||
return messages.map((message) => exportMessageAsMarkdown(message)).join('\n\n---\n\n')
|
||||
}
|
||||
|
||||
export const exportTopicAsMarkdown = async (topic: Topic) => {
|
||||
const fileName = topic.name + '.md'
|
||||
const topicMessages = await db.topics.get(topic.id)
|
||||
if (topicMessages) {
|
||||
const title = '# ' + topic.name + `\n\n`
|
||||
const markdown = exportMessagesAsMarkdown(topicMessages.messages)
|
||||
window.api.file.save(fileName, title + markdown)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user