gongxiangp2/lib/__tests__/video-local-path.test.ts
chenpei 5ef70bce4e fix: 转码按正式目录找源文件,失败只给用户可重试提示
把 /uploads 网址路径落到 UPLOAD_DIR,避免误判文件不存在。
页面和接口不再回传路径或堆栈,只提示稍后重试。
2026-08-17 15:24:13 +08:00

27 lines
912 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import path from 'path'
import { resolveLocalVideoPath } from '../video-processor'
describe('resolveLocalVideoPath', () => {
const previousUploadDir = process.env.UPLOAD_DIR
afterEach(() => {
if (previousUploadDir === undefined) delete process.env.UPLOAD_DIR
else process.env.UPLOAD_DIR = previousUploadDir
})
test('把 /uploads/ 网址路径落到 UPLOAD_DIR,而不是容器根目录的 /uploads', () => {
process.env.UPLOAD_DIR = '/app/uploads'
expect(resolveLocalVideoPath('/uploads/video-1786944507495-5131e070eb5b3827.mp4')).toBe(
path.resolve('/app/uploads/video-1786944507495-5131e070eb5b3827.mp4'),
)
})
test('已经是正式目录里的绝对路径时保持不变', () => {
process.env.UPLOAD_DIR = '/app/uploads'
expect(resolveLocalVideoPath('/app/uploads/video-source.mp4')).toBe(
path.resolve('/app/uploads/video-source.mp4'),
)
})
})