_update-payment-funid.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * 批量更新即梦 skill 的 qrCodeUrl,加入 fun_id 参数
  3. *
  4. * 使用方法:
  5. * node _update-payment-funid.js <fun_id>
  6. *
  7. * 示例:
  8. * node _update-payment-funid.js abc123def456
  9. *
  10. * 这会将所有 jimeng skill 的 qrCodeUrl 从:
  11. * https://app.fmode.cn/dev/apig-pay/?authid=T0iOotHcDX
  12. * 更新为:
  13. * https://app.fmode.cn/dev/apig-pay/?authid=T0iOotHcDX&fun_id=abc123def456
  14. *
  15. * 同时也会更新 voc 等其他分类下的 skill(如果有相同 URL 的话)
  16. */
  17. const fs = require('fs');
  18. const path = require('path');
  19. const funId = process.argv[2];
  20. if (!funId) {
  21. console.error('用法: node _update-payment-funid.js <fun_id>');
  22. console.error(' fun_id: 部署 apigRechargeOnPay 云函数后获取的 objectId');
  23. process.exit(1);
  24. }
  25. const OLD_URL = 'https://app.fmode.cn/dev/apig-pay/?authid=T0iOotHcDX';
  26. const NEW_URL = `https://app.fmode.cn/dev/apig-pay/?authid=T0iOotHcDX&fun_id=${funId}`;
  27. // 扫描所有分类目录
  28. const rootDir = path.resolve(__dirname, '..');
  29. const categories = ['jimeng', 'voc', 'social-media', 'competitor-analysis',
  30. 'review-analysis', 'synthesis', 'social-voc', 'douyin', 'video-creation'];
  31. let updated = 0;
  32. let scanned = 0;
  33. for (const category of categories) {
  34. const catDir = path.join(rootDir, category);
  35. if (!fs.existsSync(catDir)) continue;
  36. const dirs = fs.readdirSync(catDir, { withFileTypes: true })
  37. .filter(d => d.isDirectory() && !d.name.startsWith('_'));
  38. for (const dir of dirs) {
  39. const configPath = path.join(catDir, dir.name, 'api-config.json');
  40. if (!fs.existsSync(configPath)) continue;
  41. scanned++;
  42. let content = fs.readFileSync(configPath, 'utf-8');
  43. if (content.includes(OLD_URL) && !content.includes('fun_id=')) {
  44. content = content.split(OLD_URL).join(NEW_URL);
  45. fs.writeFileSync(configPath, content, 'utf-8');
  46. console.log(`[OK] ${category}/${dir.name}`);
  47. updated++;
  48. }
  49. }
  50. }
  51. console.log(`\n扫描 ${scanned} 个 skill,更新 ${updated} 个文件`);
  52. console.log(`新 URL: ${NEW_URL}`);