feat(api): add rules gen
This commit is contained in:
parent
76cd23bc0e
commit
6d09c280ac
@ -9,9 +9,33 @@ export default (server: FastifyInstance, _options: RouteShorthandOptions, done:
|
|||||||
const fetchOptions = {
|
const fetchOptions = {
|
||||||
headers: { 'Cache-Control': 'no-cache' },
|
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) {
|
} catch (error) {
|
||||||
reply.send({
|
reply.send({
|
||||||
errors: [error.message],
|
errors: [error.message],
|
||||||
|
Loading…
Reference in New Issue
Block a user