64 lines
2.5 KiB
JavaScript
64 lines
2.5 KiB
JavaScript
// e2e 测试:下载+转码+验证链接
|
|
const base = 'http://127.0.0.1:3002';
|
|
|
|
async function post(path, body) {
|
|
const res = await fetch(base + path, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) });
|
|
return res.json();
|
|
}
|
|
|
|
async function get(path) {
|
|
const res = await fetch(base + path);
|
|
return res.json();
|
|
}
|
|
|
|
const cfg = { ip: '192.168.8.241', port: 7681, httpPort: 80, user: 'admin', pass: 'ky666888', channel: 33, start: '2026-07-01T00:03:00Z', end: '2026-07-01T00:05:00Z', speed: 4, output: 'G:/gameauto/recordings/verify_link.ps' };
|
|
|
|
console.log('[1] POST /api/hikvision/download');
|
|
const { taskId, status } = await post('/api/hikvision/download', cfg);
|
|
console.log(' taskId:', taskId, 'status:', status);
|
|
|
|
console.log('[2] 轮询...');
|
|
let s;
|
|
for (let i = 0; i < 30; i++) {
|
|
await new Promise(r => setTimeout(r, 1000));
|
|
s = await get('/api/hikvision/status?taskId=' + taskId);
|
|
const mb = s.progress?.totalMB || 0;
|
|
console.log(' [' + (i + 1) + ']', s.status, mb + 'MB');
|
|
if (s.status !== 'downloading' && s.status !== 'starting') break;
|
|
}
|
|
|
|
console.log('\n========================================');
|
|
console.log(' 最终结果');
|
|
console.log('========================================');
|
|
const { result } = s;
|
|
console.log(' output :', result.output);
|
|
console.log(' size :', (result.size / 1024).toFixed(0) + 'KB');
|
|
console.log(' duration:', result.duration + 's');
|
|
console.log(' rawPs :', result.rawPs || false);
|
|
console.log(' chunks :', result.chunks || 'n/a');
|
|
|
|
const fs = await import('fs');
|
|
const filePath = result.output;
|
|
if (fs.existsSync(filePath)) {
|
|
const stat = fs.statSync(filePath);
|
|
console.log('\n ✅ 文件存在: ' + stat.size + ' bytes');
|
|
console.log(' 📁 本地路径: ' + filePath);
|
|
console.log(' 🔗 file 链接: file:///' + filePath.replace(/\\/g, '/'));
|
|
|
|
// ffprobe 验证
|
|
const { execSync } = await import('child_process');
|
|
try {
|
|
const probe = execSync('ffprobe "' + filePath + '" 2>&1', { encoding: 'utf-8', stdio: 'pipe' });
|
|
const durMatch = probe.match(/Duration: ([^,]+)/);
|
|
const vidMatch = probe.match(/Video: ([^\n]+)/);
|
|
const audMatch = probe.match(/Audio: ([^\n]+)/);
|
|
if (durMatch) console.log(' ⏱ Duration:', durMatch[1].trim());
|
|
if (vidMatch) console.log(' 🎬 Video :', vidMatch[1].trim());
|
|
if (audMatch) console.log(' 🔊 Audio :', audMatch[1].trim());
|
|
} catch (e) {
|
|
console.log(' ffprobe 失败:', e.message);
|
|
}
|
|
} else {
|
|
console.log('\n ❌ 文件不存在: ' + filePath);
|
|
}
|