From 6d09c280ac5ce5105dd5a0186a6b9ae0ed56c052 Mon Sep 17 00:00:00 2001 From: wanhose Date: Fri, 6 Sep 2024 19:25:44 +0200 Subject: [PATCH] feat(api): add rules gen --- packages/api/src/routes/v4/data.ts | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/api/src/routes/v4/data.ts b/packages/api/src/routes/v4/data.ts index a03acff..068dced 100644 --- a/packages/api/src/routes/v4/data.ts +++ b/packages/api/src/routes/v4/data.ts @@ -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],