create-test-book.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const http = require('http');
  2. console.log('创建测试书籍...');
  3. const data = JSON.stringify({
  4. title: '操作系统原理',
  5. description: '系统讲解操作系统的核心原理与设计思想,涵盖进程管理、内存管理、文件系统、设备管理、安全保护等关键模块,帮助学生建立完整的操作系统知识体系。',
  6. targetAudience: '大学生',
  7. style: '专业严谨',
  8. bookScale: '130000',
  9. knowledgeLevel: '进阶',
  10. industry: 'IT/计算机'
  11. });
  12. const options = {
  13. hostname: 'localhost',
  14. port: 3000,
  15. path: '/api/book-generator/langgraph/books',
  16. method: 'POST',
  17. headers: {
  18. 'Content-Type': 'application/json',
  19. 'Content-Length': Buffer.byteLength(data)
  20. }
  21. };
  22. const req = http.request(options, (res) => {
  23. let body = '';
  24. res.on('data', (chunk) => {
  25. body += chunk;
  26. });
  27. res.on('end', () => {
  28. console.log('响应状态:', res.statusCode);
  29. try {
  30. const responseData = JSON.parse(body);
  31. console.log('响应数据:', JSON.stringify(responseData, null, 2));
  32. if (res.statusCode === 200 && responseData.data) {
  33. console.log('\n✅ 书籍创建成功!');
  34. console.log('书籍 ID:', responseData.data.id);
  35. console.log('\n现在可以开始生成大纲了...');
  36. } else {
  37. console.log('\n❌ 创建失败:', responseData.message);
  38. }
  39. } catch (e) {
  40. console.log('响应体:', body);
  41. }
  42. });
  43. });
  44. req.on('error', (e) => {
  45. console.error('请求失败:', e.message);
  46. });
  47. req.write(data);
  48. req.end();