gongxiangp2/scripts/restore-xg0176-previews.ts
chenpei 4dba93c4e5 feat: 完成任务-详情素材迁移到新逻辑
- 迁移57个老素材到新逻辑(本地zip + S3预览图)
- 优化文件命名:SPU_作者_店铺_类型.zip
- PSD文件单独存储,不打包进all.zip
- 修复下载接口,优先使用本地zip文件
- 修复预览图重复问题
- 添加迁移脚本和验证脚本
- 更新文档和迁移计划

迁移统计:
- 总素材数:77个
- 成功迁移:57个
- 新逻辑上传:18个
- 空记录:2个
2026-01-21 10:16:28 +08:00

48 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 恢复 XG0176 的预览图记录
*/
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function main() {
console.log('='.repeat(60));
console.log('恢复 XG0176 的预览图记录');
console.log('='.repeat(60));
const materialId = 'f8148b30-d83f-4e6a-800e-fa047efd9b16';
// 查询所有 S3 预览图(assetType='main'/'sku'/'detail')
const s3Assets = await prisma.materialAsset.findMany({
where: {
materialId,
assetType: { in: ['main', 'sku', 'detail'] },
fileUrl: { startsWith: 'https://' },
},
orderBy: { sortOrder: 'asc' },
});
console.log(`找到 ${s3Assets.length} 个 S3 预览图`);
// 为每个 S3 预览图创建对应的 *-preview 记录
const newRecords = s3Assets.map((asset) => ({
materialId,
assetType: `${asset.assetType}-preview` as any,
fileUrl: asset.fileUrl,
fileName: asset.fileName,
fileSize: asset.fileSize,
sortOrder: asset.sortOrder,
}));
await prisma.materialAsset.createMany({
data: newRecords,
});
console.log(`✅ 已创建 ${newRecords.length} 条预览图记录`);
await prisma.$disconnect();
}
main();