feat(api): add rules gen

This commit is contained in:
wanhose 2024-09-06 19:25:44 +02:00
parent 76cd23bc0e
commit 6d09c280ac

View File

@ -9,9 +9,33 @@ export default (server: FastifyInstance, _options: RouteShorthandOptions, done:
const fetchOptions = {
headers: { 'Cache-Control': 'no-cache' },
};
const result = await (await fetch(databaseUrl, fetchOptions)).json();
const { rules, ...result } = await (await fetch(databaseUrl, fetchOptions)).json();
reply.send({ data: result, success: true });
reply.send({
data: {
...result,
rules: (rules as readonly string[]).map((urlFilter, index) => ({
id: index + 1,
priority: 1,
action: {
type: 'block',
},
condition: {
resourceTypes: [
'font',
'image',
'media',
'object',
'script',
'stylesheet',
'xmlhttprequest',
],
urlFilter,
},
})),
},
success: true,
});
} catch (error) {
reply.send({
errors: [error.message],