133 lines
4.5 KiB
JavaScript
133 lines
4.5 KiB
JavaScript
require('dotenv').config();
|
||
const { PrismaClient } = require('@prisma/client');
|
||
const prisma = new PrismaClient();
|
||
|
||
async function checkSlides() {
|
||
try {
|
||
console.log('\n🔍 开始检查数据库中的slides数据...\n');
|
||
|
||
// 查询所有slides,检查paragraphs
|
||
const slides = await prisma.nodeSlide.findMany({
|
||
take: 50, // 先查50条
|
||
orderBy: { createdAt: 'desc' },
|
||
include: {
|
||
node: {
|
||
select: {
|
||
title: true,
|
||
course: {
|
||
select: {
|
||
title: true
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
});
|
||
|
||
console.log(`📊 找到 ${slides.length} 条slides记录\n`);
|
||
console.log('═'.repeat(80));
|
||
|
||
let emptyTagCount = 0;
|
||
let totalParagraphs = 0;
|
||
let problemSlides = [];
|
||
|
||
for (const slide of slides) {
|
||
const content = slide.content;
|
||
if (content && content.paragraphs && Array.isArray(content.paragraphs)) {
|
||
totalParagraphs += content.paragraphs.length;
|
||
|
||
let hasProblem = false;
|
||
const problems = [];
|
||
|
||
// 检查每个paragraph
|
||
content.paragraphs.forEach((para, index) => {
|
||
if (!para || typeof para !== 'string') return;
|
||
|
||
// 检查空标签
|
||
const hasEmptyB = para.includes('<b></b>');
|
||
const hasEmptyColor = (para.includes('<color') && para.includes('></color>')) ||
|
||
(para.includes('<color') && para.includes('/>'));
|
||
const hasEmptySpan = para.includes('<span') && para.includes('></span>');
|
||
|
||
// 检查标签格式问题
|
||
const hasColorWithoutType = para.includes('<color') &&
|
||
!para.includes("type='") &&
|
||
!para.includes('type="') &&
|
||
!para.includes('></color>');
|
||
|
||
// 检查标签是否被转义
|
||
const hasEscapedTags = para.includes('<') || para.includes('>');
|
||
|
||
if (hasEmptyB || hasEmptyColor || hasEmptySpan || hasColorWithoutType || hasEscapedTags) {
|
||
hasProblem = true;
|
||
emptyTagCount++;
|
||
|
||
const issueTypes = [];
|
||
if (hasEmptyB) issueTypes.push('空<b>标签');
|
||
if (hasEmptyColor) issueTypes.push('空<color>标签');
|
||
if (hasEmptySpan) issueTypes.push('空<span>标签');
|
||
if (hasColorWithoutType) issueTypes.push('color标签缺少type属性');
|
||
if (hasEscapedTags) issueTypes.push('标签被HTML转义');
|
||
|
||
problems.push({
|
||
index,
|
||
para: para.substring(0, 150) + (para.length > 150 ? '...' : ''),
|
||
issues: issueTypes
|
||
});
|
||
}
|
||
});
|
||
|
||
if (hasProblem) {
|
||
problemSlides.push({
|
||
slideId: slide.id,
|
||
nodeTitle: slide.node?.title || 'Unknown',
|
||
courseTitle: slide.node?.course?.title || 'Unknown',
|
||
slideType: slide.slideType,
|
||
orderIndex: slide.orderIndex,
|
||
problems
|
||
});
|
||
}
|
||
}
|
||
}
|
||
|
||
// 输出统计信息
|
||
console.log('\n📈 统计信息:');
|
||
console.log(` 总slides数: ${slides.length}`);
|
||
console.log(` 总paragraphs数: ${totalParagraphs}`);
|
||
console.log(` 有问题的paragraphs数: ${emptyTagCount}`);
|
||
console.log(` 有问题的slides数: ${problemSlides.length}`);
|
||
|
||
// 输出详细问题
|
||
if (problemSlides.length > 0) {
|
||
console.log('\n⚠️ 发现的问题:');
|
||
console.log('═'.repeat(80));
|
||
|
||
problemSlides.forEach((slide, idx) => {
|
||
console.log(`\n${idx + 1}. Slide ID: ${slide.slideId}`);
|
||
console.log(` 课程: ${slide.courseTitle}`);
|
||
console.log(` 节点: ${slide.nodeTitle}`);
|
||
console.log(` 类型: ${slide.slideType}, 顺序: ${slide.orderIndex}`);
|
||
console.log(` 问题数量: ${slide.problems.length}`);
|
||
|
||
slide.problems.forEach((prob, pIdx) => {
|
||
console.log(`\n 问题 ${pIdx + 1} - Paragraph ${prob.index}:`);
|
||
console.log(` 问题类型: ${prob.issues.join(', ')}`);
|
||
console.log(` 内容预览: ${prob.para}`);
|
||
});
|
||
});
|
||
} else {
|
||
console.log('\n✅ 没有发现空标签问题!');
|
||
}
|
||
|
||
console.log('\n' + '═'.repeat(80));
|
||
|
||
} catch (error) {
|
||
console.error('❌ 错误:', error.message);
|
||
console.error(error.stack);
|
||
} finally {
|
||
await prisma.$disconnect();
|
||
}
|
||
}
|
||
|
||
checkSlides();
|