147 lines
4.3 KiB
TypeScript
147 lines
4.3 KiB
TypeScript
/**
|
|
* 验证已恢复的源文件是否可以正常下载
|
|
* 检查本地 uploads 目录中的文件在数据库中的对应素材
|
|
*/
|
|
|
|
import { PrismaClient } from '@prisma/client';
|
|
import { readdir } from 'fs/promises';
|
|
import path from 'path';
|
|
|
|
// 连接到生产数据库
|
|
const prisma = new PrismaClient({
|
|
datasources: {
|
|
db: {
|
|
url: 'postgresql://postgres:jsjj8888@192.168.58.20:5432/lobechat',
|
|
},
|
|
},
|
|
});
|
|
|
|
async function verifyRestoredFiles() {
|
|
try {
|
|
console.log('开始验证已恢复的源文件...\n');
|
|
|
|
// 读取本地 uploads 目录中的文件
|
|
const uploadsDir = path.join(process.cwd(), 'uploads');
|
|
const files = await readdir(uploadsDir);
|
|
|
|
// 过滤出音频和视频文件
|
|
const audioFiles = files.filter(f => f.endsWith('.mp3'));
|
|
const videoFiles = files.filter(f => f.endsWith('.mp4'));
|
|
|
|
console.log(`找到 ${audioFiles.length} 个音频文件`);
|
|
console.log(`找到 ${videoFiles.length} 个视频文件\n`);
|
|
|
|
// 随机抽取样本
|
|
const sampleAudio = audioFiles.sort(() => 0.5 - Math.random()).slice(0, 5);
|
|
const sampleVideo = videoFiles;
|
|
|
|
console.log('=== 抽样检测文件 ===');
|
|
console.log('\n音频文件样本:');
|
|
sampleAudio.forEach(f => console.log(` - ${f}`));
|
|
console.log('\n视频文件样本:');
|
|
sampleVideo.forEach(f => console.log(` - ${f}`));
|
|
console.log('\n');
|
|
|
|
// 查找对应的素材
|
|
const results = [];
|
|
|
|
// 检查音频文件
|
|
for (const fileName of sampleAudio) {
|
|
const filePath = `uploads/${fileName}`;
|
|
|
|
const material = await prisma.material.findFirst({
|
|
where: {
|
|
zipFilePath: filePath,
|
|
deletedAt: null,
|
|
},
|
|
select: {
|
|
id: true,
|
|
materialType: true,
|
|
productModel: true,
|
|
authorName: true,
|
|
zipFilePath: true,
|
|
},
|
|
});
|
|
|
|
results.push({
|
|
fileName,
|
|
fileType: '音频',
|
|
found: !!material,
|
|
material: material || null,
|
|
});
|
|
}
|
|
|
|
// 检查视频文件
|
|
for (const fileName of sampleVideo) {
|
|
const filePath = `/uploads/${fileName}`;
|
|
|
|
const material = await prisma.material.findFirst({
|
|
where: {
|
|
videoSourceUrl: filePath,
|
|
deletedAt: null,
|
|
},
|
|
select: {
|
|
id: true,
|
|
materialType: true,
|
|
productModel: true,
|
|
authorName: true,
|
|
videoSourceUrl: true,
|
|
},
|
|
});
|
|
|
|
results.push({
|
|
fileName,
|
|
fileType: '视频',
|
|
found: !!material,
|
|
material: material || null,
|
|
});
|
|
}
|
|
|
|
// 输出结果
|
|
console.log('=== 检测结果 ===\n');
|
|
|
|
const foundCount = results.filter(r => r.found).length;
|
|
const notFoundCount = results.filter(r => !r.found).length;
|
|
|
|
console.log(`✅ 找到对应素材: ${foundCount} 个`);
|
|
console.log(`❌ 未找到对应素材: ${notFoundCount} 个\n`);
|
|
|
|
if (foundCount > 0) {
|
|
console.log('找到的素材详情:');
|
|
console.log('-'.repeat(100));
|
|
results.filter(r => r.found).forEach((r, index) => {
|
|
console.log(`${index + 1}. ${r.fileType} - ${r.fileName}`);
|
|
console.log(` 素材ID: ${r.material!.id}`);
|
|
console.log(` 类型: ${r.material!.materialType}`);
|
|
console.log(` 型号: ${r.material!.productModel}`);
|
|
console.log(` 作者: ${r.material!.authorName}`);
|
|
console.log(` 正式环境访问: http://192.168.58.20:4320/share/${r.material!.id}`);
|
|
console.log('');
|
|
});
|
|
}
|
|
|
|
if (notFoundCount > 0) {
|
|
console.log('未找到对应素材的文件:');
|
|
console.log('-'.repeat(100));
|
|
results.filter(r => !r.found).forEach((r, index) => {
|
|
console.log(`${index + 1}. ${r.fileType} - ${r.fileName}`);
|
|
});
|
|
console.log('');
|
|
}
|
|
|
|
console.log('=== 下一步操作 ===');
|
|
console.log('1. 访问上面列出的素材详情页(正式环境)');
|
|
console.log('2. 点击下载按钮,验证是否能正常下载');
|
|
console.log('3. 如果下载成功,说明源文件已成功恢复');
|
|
console.log('');
|
|
console.log('正式系统地址: http://192.168.58.20:4320');
|
|
|
|
} catch (error) {
|
|
console.error('验证失败:', error);
|
|
} finally {
|
|
await prisma.$disconnect();
|
|
}
|
|
}
|
|
|
|
verifyRestoredFiles();
|