编辑 2:终于明白了,我使用 API 和 ID 生成器来处理 HTTPS 请求并使用提供的 &before= 参数。 &before= 参数使用日期作为参数,因此我必须从一个请求中获取最后一个操作,从中获取日期,并将其提供给 &before 参数。然后对于每个包含 1000 个元素的数组元素,我弹出最后一个元素,因为我最终会得到重复的操作。
现在,我最终得到了如下所示的操作:[[actions],[actions],[actions],[actions]] 等等,所以我使用了Merge/flatten an array of arrays 的答案来完成[actions]。然后我使用括号符号object["key"] = value 来设置/用我的HTTPS 请求中的操作替换操作,它变成了一个非常大的文件,生成这个文件花了很长时间,它出来了99.5 MB.
这是我的整个 index.js 测试文件:
const https = require('https');
const fs = require('fs');
var boardinfo = "";
https.get({
hostname: 'trello.com',
path: `/b/Vqrkz3KO.json`,
headers: {'User-Agent': `${Math.random().toString(16).substring(2,16)}`}
}, (r) => {
var data = "";
r.on('data', (d) => {
data+=d;
})
r.on('close', () => {
boardinfo = JSON.parse(data);
});
})
var actions = [];
(function untilDeath(beforeval) {
https.get({
hostname: 'api.trello.com',
path: `/1/boards/Vqrkz3KO/actions?limit=1000${beforeval ? `&before=${beforeval}` : ``}`,
headers: {'User-Agent': `${Math.random().toString(16).substring(2,16)}`}
}, (r) => {
var cmpdta = "";
r.on('data', (d) => {
cmpdta+=d;
})
r.on('close', () => {
cmpdta = JSON.parse(cmpdta);
if(cmpdta.length < 1000) {
if(cmpdta.length) actions.push(cmpdta);
return makeFile(info, [].concat.apply([], actions), fileName);
} else
untilDeath(cmpdta[999].date);
cmpdta.pop();
actions.push(cmpdta);
});
r.on('error', () => {
throw new Error('-----HTTPS Error Occurred, Please retry :(');
});
});
})();
function makeFile(trelloBoard, actions) {
trelloBoard["actions"] = actions;
fs.createWriteStream('./full-board.json');
fs.writeFile(`./full-board.json`, JSON.stringify(trelloBoard, null, `\t`), (c) => {
if(c) console.log(c);
});
}
编辑:令人失望的是,这也只能获取 1000 个操作,即使手动保存 JSON 文件,它仍然提供 1000 个操作。
我使用 HTTPS User-Agent 标头轻松解决了这个问题。
const https = require('https');
https.get({
hostname: 'trello.com',
path: '/b/Vqrkz3KO.json',
headers: {'User-Agent': 'some-random-user-agent'}
}, (r) => {
var str = "";
r.on('data', (d) => {str+=d});
r.on('close', () => {console.log(str)})
})