/** * 测试迁移查询逻辑 */ import { PrismaClient } from '@prisma/client'; const DATABASE_URL = process.env.DATABASE_URL || 'postgresql://gongxiangpan:gongxiangpan123@192.168.58.20:5432/lobechat'; const prisma = new PrismaClient({ datasources: { db: { url: DATABASE_URL, }, }, }); const VIDEO_TYPES = ['主图视频', '安装视频', '种草视频']; const AUDIO_TYPES = ['音频素材', '音乐']; function isOldStorageUrl(url: string | null): boolean { if (!url) return false; return url.includes('1080p.hk') || url.includes('jsxiangche'); } async function main() { console.log('查询视频/音频素材...'); const allMaterials = await prisma.material.findMany({ where: { materialType: { in: [...VIDEO_TYPES, ...AUDIO_TYPES], }, deletedAt: null, }, select: { id: true, productModel: true, materialType: true, previewUrl: true, videoCoverUrl: true, videoPreview540Url: true, videoPreviewClipUrl: true, } as any, take: 10, }); console.log(`找到 ${allMaterials.length} 个素材`); console.log(); const oldStorageMaterials = allMaterials.filter(material => { return isOldStorageUrl((material as any).previewUrl) || isOldStorageUrl((material as any).videoCoverUrl) || isOldStorageUrl((material as any).videoPreview540Url) || isOldStorageUrl((material as any).videoPreviewClipUrl); }); console.log(`使用旧存储桶的素材: ${oldStorageMaterials.length} 个`); console.log(); oldStorageMaterials.forEach((m, i) => { console.log(`${i + 1}. ${(m as any).productModel} (${(m as any).materialType})`); if ((m as any).previewUrl && isOldStorageUrl((m as any).previewUrl)) { console.log(` previewUrl: ${(m as any).previewUrl}`); } if ((m as any).videoCoverUrl && isOldStorageUrl((m as any).videoCoverUrl)) { console.log(` videoCoverUrl: ${(m as any).videoCoverUrl}`); } }); await prisma.$disconnect(); } main();