/** * 分析老素材情况 * 查询所有老素材(2025-10-27之前)的数量和文件路径 */ import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient(); async function analyzeOldMaterials() { try { console.log('开始分析老素材情况...\n'); // 老素材分界点 const oldMaterialDate = new Date('2025-10-27T23:59:59.999Z'); // 1. 统计老素材总数 const oldMaterialsCount = await prisma.material.count({ where: { createdAt: { lte: oldMaterialDate }, deletedAt: null, }, }); console.log(`📊 老素材总数: ${oldMaterialsCount}`); // 2. 按素材类型统计 const materialsByType = await prisma.material.groupBy({ by: ['materialType'], where: { createdAt: { lte: oldMaterialDate }, deletedAt: null, }, _count: true, }); console.log('\n📋 按素材类型统计:'); materialsByType.forEach((item) => { console.log(` - ${item.materialType}: ${item._count} 个`); }); // 3. 查询有源文件的老素材(zipFilePath 不为空) const oldMaterialsWithFiles = await prisma.material.findMany({ where: { createdAt: { lte: oldMaterialDate }, deletedAt: null, zipFilePath: { not: '' }, }, select: { id: true, materialType: true, zipFilePath: true, zipFileName: true, previewUrl: true, createdAt: true, }, take: 10, // 只取前10个样本 }); console.log(`\n📦 有源文件的老素材: ${oldMaterialsWithFiles.length > 0 ? '样本' : '无'}`); if (oldMaterialsWithFiles.length > 0) { console.log('\n样本数据(前10个):'); oldMaterialsWithFiles.forEach((material, index) => { console.log(`\n [${index + 1}] ${material.materialType}`); console.log(` ID: ${material.id}`); console.log(` 文件路径: ${material.zipFilePath}`); console.log(` 文件名: ${material.zipFileName}`); console.log(` 预览图: ${material.previewUrl.substring(0, 80)}...`); console.log(` 创建时间: ${material.createdAt.toISOString()}`); }); } // 4. 统计不同路径模式的老素材 const allOldMaterials = await prisma.material.findMany({ where: { createdAt: { lte: oldMaterialDate }, deletedAt: null, }, select: { zipFilePath: true, previewUrl: true, }, }); const pathPatterns = { http103: 0, // http://103.118.245.6/... uploadsRelative: 0, // uploads/material-*.zip empty: 0, // 空路径 other: 0, // 其他 }; allOldMaterials.forEach((material) => { const path = material.zipFilePath || ''; if (path.includes('103.118.245.6')) { pathPatterns.http103++; } else if (path.startsWith('uploads/')) { pathPatterns.uploadsRelative++; } else if (path === '') { pathPatterns.empty++; } else { pathPatterns.other++; } }); console.log('\n\n📁 老素材文件路径模式统计:'); console.log(` - 包含 103.118.245.6: ${pathPatterns.http103} 个`); console.log(` - uploads/ 相对路径: ${pathPatterns.uploadsRelative} 个`); console.log(` - 空路径: ${pathPatterns.empty} 个`); console.log(` - 其他: ${pathPatterns.other} 个`); // 5. 检查预览图URL模式 const previewUrlPatterns = { old: 0, // s3.1080p.hk/jsxiangche new: 0, // s3.yydd.ai/gongxiangpan/由壹点AI/ other: 0, }; allOldMaterials.forEach((material) => { const url = material.previewUrl || ''; if (url.includes('s3.1080p.hk') || url.includes('jsxiangche')) { previewUrlPatterns.old++; } else if (url.includes('由壹点AI/')) { previewUrlPatterns.new++; } else { previewUrlPatterns.other++; } }); console.log('\n\n🖼️ 老素材预览图URL模式统计:'); console.log(` - 老S3 (s3.1080p.hk/jsxiangche): ${previewUrlPatterns.old} 个`); console.log(` - 新S3 (由壹点AI/): ${previewUrlPatterns.new} 个`); console.log(` - 其他: ${previewUrlPatterns.other} 个`); console.log('\n\n✅ 分析完成!'); console.log('\n💡 结论:'); console.log(' - 如果 "uploads/ 相对路径" 数量 > 0,这些文件在 192.168.58.20 上已丢失'); console.log(' - 如果 "包含 103.118.245.6" 数量 > 0,需要检查外网服务器文件是否还在'); console.log(' - 预览图在 S3 上,应该还在(除非 S3 也被清理了)'); } catch (error) { console.error('❌ 分析失败:', error); } finally { await prisma.$disconnect(); } } analyzeOldMaterials();