fix(api): v2 data endpoint

This commit is contained in:
wanhose 2024-04-03 19:26:01 +02:00
parent 81b50b1798
commit 5d45679da6

View File

@ -8,7 +8,7 @@ export default (server: FastifyInstance, options: RouteShorthandOptions, done: (
const commonWordsUrl = `${dataUrl}/common-words.json`; const commonWordsUrl = `${dataUrl}/common-words.json`;
const fixesUrl = `${dataUrl}/fixes.txt`; const fixesUrl = `${dataUrl}/fixes.txt`;
const skipsUrl = `${dataUrl}/skips.json`; const skipsUrl = `${dataUrl}/skips.json`;
const tokensUrl = `${dataUrl}/tokens.txt`; const tokensUrl = `${dataUrl}/tokens.json`;
const results = await Promise.all([ const results = await Promise.all([
fetch(commonWordsUrl), fetch(commonWordsUrl),
@ -16,19 +16,22 @@ export default (server: FastifyInstance, options: RouteShorthandOptions, done: (
fetch(skipsUrl), fetch(skipsUrl),
fetch(tokensUrl), fetch(tokensUrl),
]); ]);
const skips = await results[2].json();
const tokens = await results[3].json();
reply.send({ reply.send({
data: { data: {
classes: (await results[3].json()).classes, classes: tokens.classes,
commonWords: await results[0].json(), commonWords: await results[0].json(),
elements: (await results[3].json()).selectors, elements: tokens.selectors,
fixes: (await results[1].text()).split('\n').filter((x) => !!x), fixes: (await results[1].text()).split('\n').filter((x) => !!x),
skips: (await results[2].json()).domains, skips: skips.domains,
tags: (await results[2].json()).tags, tags: skips.tags,
}, },
success: true, success: true,
}); });
} catch { } catch (e) {
console.error(e);
reply.send({ success: false }); reply.send({ success: false });
} }
}); });