mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-03-25 15:25:50 +00:00
fix:修复了导出时媒体导出出错的问题
This commit is contained in:
@@ -721,6 +721,22 @@ class ExportService {
|
|||||||
return '.jpg'
|
return '.jpg'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getMediaLayout(outputPath: string, options: ExportOptions): {
|
||||||
|
exportMediaEnabled: boolean
|
||||||
|
mediaRootDir: string
|
||||||
|
mediaRelativePrefix: string
|
||||||
|
} {
|
||||||
|
const exportMediaEnabled = options.exportMedia === true &&
|
||||||
|
Boolean(options.exportImages || options.exportVoices || options.exportEmojis)
|
||||||
|
const outputDir = path.dirname(outputPath)
|
||||||
|
const outputBaseName = path.basename(outputPath, path.extname(outputPath))
|
||||||
|
const useSharedMediaLayout = options.sessionLayout === 'shared'
|
||||||
|
const mediaRelativePrefix = useSharedMediaLayout
|
||||||
|
? path.posix.join('media', outputBaseName)
|
||||||
|
: 'media'
|
||||||
|
return { exportMediaEnabled, mediaRootDir: outputDir, mediaRelativePrefix }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载文件
|
* 下载文件
|
||||||
*/
|
*/
|
||||||
@@ -1145,6 +1161,8 @@ class ExportService {
|
|||||||
phase: 'exporting'
|
phase: 'exporting'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const { exportMediaEnabled, mediaRootDir, mediaRelativePrefix } = this.getMediaLayout(outputPath, options)
|
||||||
|
const mediaCache = new Map<string, MediaExportItem | null>()
|
||||||
const chatLabMessages: ChatLabMessage[] = []
|
const chatLabMessages: ChatLabMessage[] = []
|
||||||
for (const msg of allMessages) {
|
for (const msg of allMessages) {
|
||||||
const memberInfo = collected.memberSet.get(msg.senderUsername)?.member || {
|
const memberInfo = collected.memberSet.get(msg.senderUsername)?.member || {
|
||||||
@@ -1154,8 +1172,20 @@ class ExportService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let content = this.parseMessageContent(msg.content, msg.localType)
|
let content = this.parseMessageContent(msg.content, msg.localType)
|
||||||
// 如果是语音消息且开启了转文字
|
if (exportMediaEnabled) {
|
||||||
|
const mediaKey = `${msg.localType}_${msg.localId}`
|
||||||
|
if (!mediaCache.has(mediaKey)) {
|
||||||
|
const mediaItem = await this.exportMediaForMessage(msg, sessionId, mediaRootDir, mediaRelativePrefix, {
|
||||||
|
exportImages: options.exportImages,
|
||||||
|
exportVoices: options.exportVoices,
|
||||||
|
exportEmojis: options.exportEmojis,
|
||||||
|
exportVoiceAsText: options.exportVoiceAsText
|
||||||
|
})
|
||||||
|
mediaCache.set(mediaKey, mediaItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
if (msg.localType === 34 && options.exportVoiceAsText) {
|
if (msg.localType === 34 && options.exportVoiceAsText) {
|
||||||
|
// 如果是语音消息且开启了转文字
|
||||||
content = await this.transcribeVoice(sessionId, String(msg.localId))
|
content = await this.transcribeVoice(sessionId, String(msg.localId))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1261,6 +1291,8 @@ class ExportService {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const collected = await this.collectMessages(sessionId, cleanedMyWxid, options.dateRange)
|
const collected = await this.collectMessages(sessionId, cleanedMyWxid, options.dateRange)
|
||||||
|
const { exportMediaEnabled, mediaRootDir, mediaRelativePrefix } = this.getMediaLayout(outputPath, options)
|
||||||
|
const mediaCache = new Map<string, MediaExportItem | null>()
|
||||||
const allMessages: any[] = []
|
const allMessages: any[] = []
|
||||||
|
|
||||||
for (const msg of collected.rows) {
|
for (const msg of collected.rows) {
|
||||||
@@ -1269,7 +1301,24 @@ class ExportService {
|
|||||||
const source = sourceMatch ? sourceMatch[0] : ''
|
const source = sourceMatch ? sourceMatch[0] : ''
|
||||||
|
|
||||||
let content = this.parseMessageContent(msg.content, msg.localType)
|
let content = this.parseMessageContent(msg.content, msg.localType)
|
||||||
if (msg.localType === 34 && options.exportVoiceAsText) {
|
let mediaItem: MediaExportItem | null = null
|
||||||
|
if (exportMediaEnabled) {
|
||||||
|
const mediaKey = `${msg.localType}_${msg.localId}`
|
||||||
|
if (mediaCache.has(mediaKey)) {
|
||||||
|
mediaItem = mediaCache.get(mediaKey) || null
|
||||||
|
} else {
|
||||||
|
mediaItem = await this.exportMediaForMessage(msg, sessionId, mediaRootDir, mediaRelativePrefix, {
|
||||||
|
exportImages: options.exportImages,
|
||||||
|
exportVoices: options.exportVoices,
|
||||||
|
exportEmojis: options.exportEmojis,
|
||||||
|
exportVoiceAsText: options.exportVoiceAsText
|
||||||
|
})
|
||||||
|
mediaCache.set(mediaKey, mediaItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mediaItem) {
|
||||||
|
content = mediaItem.relativePath
|
||||||
|
} else if (msg.localType === 34 && options.exportVoiceAsText) {
|
||||||
content = await this.transcribeVoice(sessionId, String(msg.localId))
|
content = await this.transcribeVoice(sessionId, String(msg.localId))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1499,14 +1548,7 @@ class ExportService {
|
|||||||
const sortedMessages = collected.rows.sort((a, b) => a.createTime - b.createTime)
|
const sortedMessages = collected.rows.sort((a, b) => a.createTime - b.createTime)
|
||||||
|
|
||||||
// 媒体导出设置
|
// 媒体导出设置
|
||||||
const exportMediaEnabled = options.exportImages || options.exportVoices || options.exportEmojis
|
const { exportMediaEnabled, mediaRootDir, mediaRelativePrefix } = this.getMediaLayout(outputPath, options)
|
||||||
const outputDir = path.dirname(outputPath)
|
|
||||||
const outputBaseName = path.basename(outputPath, path.extname(outputPath))
|
|
||||||
const useSharedMediaLayout = options.sessionLayout === 'shared'
|
|
||||||
const mediaRelativePrefix = useSharedMediaLayout
|
|
||||||
? path.posix.join('media', outputBaseName)
|
|
||||||
: 'media'
|
|
||||||
const mediaRootDir = outputDir
|
|
||||||
|
|
||||||
// 媒体导出缓存
|
// 媒体导出缓存
|
||||||
const mediaCache = new Map<string, MediaExportItem | null>()
|
const mediaCache = new Map<string, MediaExportItem | null>()
|
||||||
|
|||||||
Reference in New Issue
Block a user