001project_wildgrowth/backend/scripts/test-notebook-cover.sh

61 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# 测试笔记本封面获取逻辑
SERVER_IP="120.55.112.195"
SERVER_USER="root"
SERVER_PASS="yangyichenYANGYICHENkaifa859"
sshpass -p "$SERVER_PASS" ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP << 'REMOTE_SCRIPT'
cd /var/www/wildgrowth-backend/backend
node -e "
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
(async () => {
try {
const notebookId = 'b8f11787-9529-476a-9c31-717001b96cd8';
// 1. 查询笔记本
const notebook = await prisma.notebook.findUnique({
where: { id: notebookId },
select: { id: true, title: true, coverImage: true },
});
console.log('1. 笔记本信息:');
console.log(JSON.stringify(notebook, null, 2));
// 2. 提取课程名称
const courseName = notebook.title.replace(/《/g, '').replace(/》/g, '').trim();
console.log('\\n2. 提取的课程名称:', courseName);
// 3. 查找匹配的课程
const course = await prisma.course.findFirst({
where: { title: courseName },
select: { id: true, title: true, coverImage: true },
});
console.log('\\n3. 匹配的课程:');
console.log(JSON.stringify(course, null, 2));
// 4. 模拟代码逻辑
let coverImage = notebook.coverImage;
console.log('\\n4. 初始封面:', coverImage || 'null');
if (!coverImage || (coverImage && coverImage.trim() === '')) {
console.log(' 进入封面获取逻辑');
if (course && course.coverImage) {
coverImage = course.coverImage;
console.log(' 更新封面为:', coverImage);
}
}
console.log('\\n5. 最终封面:', coverImage || 'null');
} catch (error) {
console.error('错误:', error);
} finally {
await prisma.\$disconnect();
}
})();
"
REMOTE_SCRIPT