probe-ultimate-inspect.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env node
  2. // 扫描 data/probe-ultimate/*.json,打印每个端点的 data 结构核心要点
  3. const fs = require('fs');
  4. const path = require('path');
  5. const DIR = path.join('data', 'probe-ultimate');
  6. const files = fs.readdirSync(DIR).filter((f) => f.endsWith('.json') && f !== '_overview.json').sort();
  7. function inspect(name, json) {
  8. const sj = json.sampleJson || {};
  9. const d = sj.data;
  10. if (!d) return { _nodata: true };
  11. // TikHub 常见二级嵌套 data.data
  12. const inner = d.data || d;
  13. if (!inner || typeof inner !== 'object') return { _notobj: typeof inner };
  14. const keys = Object.keys(inner);
  15. const report = { topLevelKeys: keys };
  16. // 最常见:objs / user_list / data / list / items
  17. for (const arrKey of ['objs', 'user_list', 'data', 'list', 'items', 'hot_search_word_list', 'word_list', 'account_list', 'aweme_list']) {
  18. if (Array.isArray(inner[arrKey])) {
  19. const arr = inner[arrKey];
  20. report.arrKey = arrKey;
  21. report.len = arr.length;
  22. report.firstItemKeys = arr[0] ? Object.keys(arr[0]).slice(0, 12) : [];
  23. report.firstItemSample = arr[0] ? JSON.stringify(arr[0]).slice(0, 400) : null;
  24. break;
  25. }
  26. }
  27. return report;
  28. }
  29. const summary = {};
  30. for (const f of files) {
  31. const p = path.join(DIR, f);
  32. const j = JSON.parse(fs.readFileSync(p, 'utf-8'));
  33. if (j.status !== 200) { summary[j.name] = { status: j.status, ok: false }; continue; }
  34. summary[j.name] = { status: 200, path: j.path, body: j.body, params: j.params, ...inspect(j.name, j) };
  35. }
  36. // 分组打印
  37. const groups = {
  38. 'A-douyin-billboard': ['fetch_hot_total_video_list', 'fetch_hot_total_topic_list', 'fetch_hot_total_search_list', 'fetch_hot_total_hot_word_list', 'fetch_hot_total_high_fan_list', 'fetch_hot_total_high_like_list', 'fetch_hot_total_high_play_list', 'fetch_hot_total_high_topic_list', 'fetch_hot_total_high_search_list', 'fetch_hot_account_list', 'fetch_hot_calendar_list', 'web_fetch_hot_search_result'],
  39. 'B-tiktok-ads': ['get_keyword_list', 'get_keyword_details', 'get_keyword_insights', 'get_related_keywords', 'get_top_products', 'get_top_ads_spotlight', 'get_creator_list', 'search_creators'],
  40. };
  41. for (const [g, names] of Object.entries(groups)) {
  42. console.log(`\n=========== ${g} ===========`);
  43. for (const n of names) {
  44. const s = summary[n];
  45. if (!s) { console.log(` ${n}: NOT FOUND`); continue; }
  46. console.log(`\n ▸ ${n}`);
  47. console.log(` path: ${s.path}`);
  48. if (s.status !== 200) { console.log(` status: ${s.status} ✗`); continue; }
  49. console.log(` topLevelKeys: ${JSON.stringify(s.topLevelKeys)}`);
  50. if (s.arrKey) {
  51. console.log(` arrKey=${s.arrKey} len=${s.len}`);
  52. console.log(` firstItemKeys: ${JSON.stringify(s.firstItemKeys)}`);
  53. console.log(` firstItemSample: ${s.firstItemSample}`);
  54. } else {
  55. console.log(` (no array list found at top level)`);
  56. }
  57. }
  58. }