I'm creating a REST API that gets raw data from the internet then apply a REGEX to it and return it in JSON format.(我正在创建一个REST API,该API可从互联网获取原始数据,然后对其应用REGEX并以JSON格式返回。)
this is my function for getting Data as JSON.(这是我将数据作为JSON获取的功能。)
first i'm using got() to get the raw data than I apply ANIME_LIST_REGEX.exec() to filter it with the regular expression to make it in JSON format.(首先,我使用got()获取原始数据,而不是应用ANIME_LIST_REGEX.exec()以正则表达式对其进行过滤以使其成为JSON格式。)
async function getAnimeList(url) {
const {body} = await got(url);
let ANIME_LIST_DATA = ANIME_LIST_REGEX.exec(body)
if (!ANIME_LIST_DATA) {
return null;
}
return {
animeList: ANIME_LIST_DATA[1]
};
}(})
in this endpoint I'm retreiving the data from the 1st function and parsing the JSON, the return it as a response.(在这个端点中,我要从第一个函数检索数据并解析JSON,然后将其作为响应返回。)
app.get('/anime-list', async (req, res, next) => {
const appData = await getAnimeList(URL_BASE_ANIME_LIST);
var listJson = JSON5.parse(appData.animeList)
res.json(listJson)
})
The issue is that the returned array is pretty big (5000 entries of js objects) and the request takes long time to return and show the array(问题是返回的数组很大(js对象有5000个条目),请求需要很长时间才能返回并显示该数组)
What I want to do is to return a chunck of that array every time I call the function or reach the endpoint.(我想做的是每次我调用函数或到达端点时都返回该数组的块。)
Tried several methods but none of them made sense.(尝试了几种方法,但没有一种是有意义的。)
Does anyone got an idea?(有人知道吗?)
ask by faouzi Ch translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…