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

49 lines
1.2 KiB
Bash
Executable File
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.

#!/bin/bash
# 测试笔记本API查看实际返回
SERVER_IP="120.55.112.195"
SERVER_USER="root"
SERVER_PASS="yangyichenYANGYICHENkaifa859"
echo "🔍 测试笔记本API..."
echo ""
sshpass -p "$SERVER_PASS" ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP << 'REMOTE_SCRIPT'
cd /var/www/wildgrowth-backend/backend
# 获取一个测试token从数据库
TOKEN=$(node -e "
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
const jwt = require('jsonwebtoken');
(async () => {
try {
const user = await prisma.user.findFirst({
where: { id: 'def0ffdc-d078-490c-b713-6462d1027a77' },
});
if (user) {
const token = jwt.sign(
{ userId: user.id },
process.env.JWT_SECRET || 'your-secret-key',
{ expiresIn: '7d' }
);
console.log(token);
}
} catch (error) {
console.error('Error:', error);
} finally {
await prisma.\$disconnect();
}
})();
")
echo "📝 调用API..."
curl -s -H "Authorization: Bearer $TOKEN" http://localhost:3000/api/notebooks | python3 -m json.tool
echo ""
echo "📊 查看最新日志..."
pm2 logs wildgrowth-api --lines 20 --nostream | grep -E "\[DEBUG\]|\[Notebook\]|console.log" | tail -10
REMOTE_SCRIPT