MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / exportConversation

Function exportConversation

src/utils/conversationExport.ts:143–174  ·  view source on GitHub ↗
(
  title: string,
  messages: ExportMessage[],
  createdAt: number,
  format: ExportFormat,
  labels: ExportLabels
)

Source from the content-addressed store, hash-verified

141 * 导出对话到下载目录
142 */
143export async function exportConversation(
144 title: string,
145 messages: ExportMessage[],
146 createdAt: number,
147 format: ExportFormat,
148 labels: ExportLabels
149): Promise<{ success: boolean; filePath?: string; error?: string }> {
150 if (messages.length === 0) {
151 return { success: false, error: 'No messages to export' }
152 }
153
154 // 格式化内容
155 let content: string
156 let filename: string
157 const timestamp = dayjs(createdAt).format('YYYYMMDD_HHmmss')
158 const safeTitle = sanitizeFilename(title)
159
160 if (format === 'markdown') {
161 content = formatAsMarkdown(title, messages, createdAt, labels)
162 filename = `${safeTitle}_${timestamp}.md`
163 } else {
164 content = formatAsPlainText(title, messages, createdAt, labels)
165 filename = `${safeTitle}_${timestamp}.txt`
166 }
167
168 // 转换为 data URL 并保存
169 const dataUrl = `data:text/plain;charset=utf-8,${encodeURIComponent(content)}`
170 const { useCacheService } = await import('@/services/cache/service')
171 const result = await useCacheService().saveToDownloads(filename, dataUrl)
172
173 return result
174}

Callers

nothing calls this directly

Calls 5

sanitizeFilenameFunction · 0.85
formatAsMarkdownFunction · 0.85
formatAsPlainTextFunction · 0.85
useCacheServiceFunction · 0.85
saveToDownloadsMethod · 0.65

Tested by

no test coverage detected