fix(cleaner): capture video reference before page close for rename
page.video() may return null after page.close(), so the video reference must be captured before closing the detail page. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1278,25 +1278,24 @@ export class CleanerService {
|
|||||||
})
|
})
|
||||||
|
|
||||||
log.debug('[详情页面清理] 准备关闭详情页面', { pageUrl: detailPage.url() })
|
log.debug('[详情页面清理] 准备关闭详情页面', { pageUrl: detailPage.url() })
|
||||||
|
// Capture video reference before closing — page.video() may return null after close
|
||||||
|
const video = this.videoDir ? detailPage.video() : null
|
||||||
await detailPage.close()
|
await detailPage.close()
|
||||||
log.debug('[详情页面清理完成] 详情页已关闭')
|
log.debug('[详情页面清理完成] 详情页已关闭')
|
||||||
|
|
||||||
// Rename video file to order number if video recording is enabled
|
// Rename video file to order number if video recording is enabled
|
||||||
if (this.videoDir && expectedOrderNumber) {
|
if (video && expectedOrderNumber) {
|
||||||
try {
|
try {
|
||||||
const video = detailPage.video()
|
const originalPath = await video.path()
|
||||||
if (video) {
|
if (originalPath && fs.existsSync(originalPath)) {
|
||||||
const originalPath = await video.path()
|
const ext = path.extname(originalPath) || '.webm'
|
||||||
if (originalPath && fs.existsSync(originalPath)) {
|
const orderVideoPath = path.join(this.videoDir!, `${expectedOrderNumber}${ext}`)
|
||||||
const ext = path.extname(originalPath) || '.webm'
|
// Avoid overwriting existing file (e.g. retry)
|
||||||
const orderVideoPath = path.join(this.videoDir, `${expectedOrderNumber}${ext}`)
|
const finalPath = fs.existsSync(orderVideoPath)
|
||||||
// Avoid overwriting existing file (e.g. retry)
|
? path.join(this.videoDir!, `${expectedOrderNumber}_${Date.now()}${ext}`)
|
||||||
const finalPath = fs.existsSync(orderVideoPath)
|
: orderVideoPath
|
||||||
? path.join(this.videoDir, `${expectedOrderNumber}_${Date.now()}${ext}`)
|
fs.renameSync(originalPath, finalPath)
|
||||||
: orderVideoPath
|
log.debug('[视频录制] 视频已重命名', { from: originalPath, to: finalPath })
|
||||||
fs.renameSync(originalPath, finalPath)
|
|
||||||
log.debug('[视频录制] 视频已重命名', { from: originalPath, to: finalPath })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (videoError) {
|
} catch (videoError) {
|
||||||
log.warn('[视频录制] 重命名视频失败', {
|
log.warn('[视频录制] 重命名视频失败', {
|
||||||
|
|||||||
Reference in New Issue
Block a user