( db: DatabaseAdapter, params: ExportFilterParams, writer: ExportWriter, progress?: ExportProgressCallback )
| 270 | // ==================== Session mode ==================== |
| 271 | |
| 272 | function exportSessionMode( |
| 273 | db: DatabaseAdapter, |
| 274 | params: ExportFilterParams, |
| 275 | writer: ExportWriter, |
| 276 | progress?: ExportProgressCallback |
| 277 | ): { totalMessages: number; blockIndex: number } { |
| 278 | if (!params.segmentIds || params.segmentIds.length === 0) { |
| 279 | writer.write(`## Statistics\n\n- No sessions selected\n`) |
| 280 | writer.end() |
| 281 | return { totalMessages: 0, blockIndex: 0 } |
| 282 | } |
| 283 | |
| 284 | progress?.({ |
| 285 | stage: 'preparing', |
| 286 | currentBlock: 0, |
| 287 | totalBlocks: params.segmentIds.length, |
| 288 | percentage: 10, |
| 289 | message: `Preparing to export ${params.segmentIds.length} sessions...`, |
| 290 | }) |
| 291 | |
| 292 | const sessionsSql = ` |
| 293 | SELECT id, start_ts as startTs, end_ts as endTs |
| 294 | FROM segment |
| 295 | WHERE id IN (${params.segmentIds.map(() => '?').join(',')}) |
| 296 | ORDER BY start_ts ASC |
| 297 | ` |
| 298 | const sessions = db.prepare(sessionsSql).all(...params.segmentIds) as Array<{ |
| 299 | id: number |
| 300 | startTs: number |
| 301 | endTs: number |
| 302 | }> |
| 303 | |
| 304 | const totalBlocks = sessions.length |
| 305 | writer.write(`## Statistics\n\n- Blocks: ${totalBlocks}\n\n`) |
| 306 | writer.write(`## Conversation Content\n\n`) |
| 307 | |
| 308 | const messagesSql = ` |
| 309 | SELECT msg.id, |
| 310 | COALESCE(m.group_nickname, m.account_name, m.platform_id) as senderName, |
| 311 | msg.content, |
| 312 | msg.ts as timestamp |
| 313 | FROM message_context mc |
| 314 | JOIN message msg ON msg.id = mc.message_id |
| 315 | JOIN member m ON msg.sender_id = m.id |
| 316 | WHERE mc.segment_id = ? |
| 317 | ORDER BY msg.ts ASC |
| 318 | ` |
| 319 | |
| 320 | let totalMessages = 0 |
| 321 | let blockIndex = 0 |
| 322 | |
| 323 | for (const session of sessions) { |
| 324 | blockIndex++ |
| 325 | progress?.({ |
| 326 | stage: 'exporting', |
| 327 | currentBlock: blockIndex, |
| 328 | totalBlocks, |
| 329 | percentage: Math.round(15 + ((blockIndex - 1) / totalBlocks) * 80), |
no test coverage detected