128 lines
3.8 KiB
TypeScript
128 lines
3.8 KiB
TypeScript
/**
|
||
* 检查已迁移素材的URL格式是否正确
|
||
* 查找包含jsxiangche的错误URL
|
||
*/
|
||
|
||
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 = ['音频素材', '音乐'];
|
||
|
||
async function main() {
|
||
console.log('='.repeat(60));
|
||
console.log('检查已迁移素材的URL格式');
|
||
console.log('='.repeat(60));
|
||
console.log();
|
||
|
||
try {
|
||
// 查询所有视频/音频素材
|
||
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,
|
||
});
|
||
|
||
console.log(`查询到 ${allMaterials.length} 个视频/音频素材`);
|
||
console.log();
|
||
|
||
// 查找已迁移到新存储桶但URL格式错误的素材
|
||
const problematicMaterials: Array<{
|
||
id: string;
|
||
productModel: string;
|
||
materialType: string;
|
||
fields: Array<{ name: string; url: string }>;
|
||
}> = [];
|
||
|
||
for (const material of allMaterials) {
|
||
const m = material as any;
|
||
const problematicFields: Array<{ name: string; url: string }> = [];
|
||
|
||
// 检查各个URL字段
|
||
const urlFields = [
|
||
{ name: 'previewUrl', value: m.previewUrl },
|
||
{ name: 'videoCoverUrl', value: m.videoCoverUrl },
|
||
{ name: 'videoPreview540Url', value: m.videoPreview540Url },
|
||
{ name: 'videoPreviewClipUrl', value: m.videoPreviewClipUrl },
|
||
];
|
||
|
||
for (const field of urlFields) {
|
||
if (field.value) {
|
||
// 如果URL指向新存储桶(s3.yydd.ai),但包含jsxiangche,说明格式错误
|
||
if (field.value.includes('s3.yydd.ai') && field.value.includes('jsxiangche')) {
|
||
problematicFields.push({ name: field.name, url: field.value });
|
||
}
|
||
}
|
||
}
|
||
|
||
if (problematicFields.length > 0) {
|
||
problematicMaterials.push({
|
||
id: m.id,
|
||
productModel: m.productModel,
|
||
materialType: m.materialType,
|
||
fields: problematicFields,
|
||
});
|
||
}
|
||
}
|
||
|
||
console.log(`找到 ${problematicMaterials.length} 个URL格式错误的已迁移素材`);
|
||
console.log();
|
||
|
||
if (problematicMaterials.length > 0) {
|
||
console.log('❌ URL格式错误的素材列表:');
|
||
console.log();
|
||
|
||
problematicMaterials.forEach((m, i) => {
|
||
console.log(`${i + 1}. 素材ID: ${m.id}`);
|
||
console.log(` 产品型号: ${m.productModel}`);
|
||
console.log(` 素材类型: ${m.materialType}`);
|
||
console.log(` 错误字段:`);
|
||
m.fields.forEach(field => {
|
||
console.log(` - ${field.name}: ${field.url}`);
|
||
});
|
||
console.log();
|
||
});
|
||
|
||
console.log('='.repeat(60));
|
||
console.log('总结');
|
||
console.log('='.repeat(60));
|
||
console.log(`总素材数: ${allMaterials.length}`);
|
||
console.log(`URL格式错误: ${problematicMaterials.length} 个`);
|
||
console.log(`需要修复的URL字段总数: ${problematicMaterials.reduce((sum, m) => sum + m.fields.length, 0)} 个`);
|
||
console.log();
|
||
console.log('⚠️ 这些素材的URL需要修复!');
|
||
} else {
|
||
console.log('✅ 所有已迁移素材的URL格式都正确!');
|
||
}
|
||
|
||
} catch (error) {
|
||
console.error('执行失败:', error);
|
||
process.exit(1);
|
||
} finally {
|
||
await prisma.$disconnect();
|
||
}
|
||
}
|
||
|
||
main();
|