mirror of
https://github.com/Nezumi-2711/cloudflare-gateway-pihole-scripts.git
synced 2026-09-22 13:38:37 +00:00
updated logging for API calls
This commit is contained in:
+33
-20
@@ -62,7 +62,6 @@ export const createZeroTrustListsOneByOne = async (items) => {
|
||||
* @param {string[]} items The domains.
|
||||
*/
|
||||
export const createZeroTrustListsAtOnce = async (items) => {
|
||||
const totalListNumber = Math.ceil(items.length / LIST_ITEM_SIZE);
|
||||
const requests = [];
|
||||
|
||||
for (let i = 0, listNumber = 1; i < items.length; i += LIST_ITEM_SIZE) {
|
||||
@@ -77,7 +76,7 @@ export const createZeroTrustListsAtOnce = async (items) => {
|
||||
|
||||
try {
|
||||
await Promise.all(requests);
|
||||
console.log(`Created ${totalListNumber} lists`);
|
||||
console.log("Created lists successfully");
|
||||
} catch (err) {
|
||||
console.error(`Error occurred while creating lists - ${err.toString()}`);
|
||||
}
|
||||
@@ -125,7 +124,7 @@ export const deleteZeroTrustListsAtOnce = async (lists) => {
|
||||
|
||||
try {
|
||||
await Promise.all(requests);
|
||||
console.log(`Deleted ${lists.length} lists`);
|
||||
console.log("Deleted lists successfully");
|
||||
} catch (err) {
|
||||
console.error(`Error occurred while deleting lists - ${err.toString()}`);
|
||||
}
|
||||
@@ -147,19 +146,26 @@ export const getZeroTrustRules = () =>
|
||||
* @param {string} wirefilterExpression The expression to be used for the rule.
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
export const createZeroTrustRule = (wirefilterExpression) =>
|
||||
requestGateway("/rules", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
name: "CGPS Filter Lists",
|
||||
description:
|
||||
"Filter lists created by Cloudflare Gateway Pi-hole Scripts. Avoid editing this rule. Changing the name of this rule will break the script.",
|
||||
enabled: true,
|
||||
action: "block",
|
||||
filters: ["dns"],
|
||||
traffic: wirefilterExpression,
|
||||
}),
|
||||
});
|
||||
export const createZeroTrustRule = async (wirefilterExpression) => {
|
||||
try {
|
||||
await requestGateway("/rules", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
name: "CGPS Filter Lists",
|
||||
description:
|
||||
"Filter lists created by Cloudflare Gateway Pi-hole Scripts. Avoid editing this rule. Changing the name of this rule will break the script.",
|
||||
enabled: true,
|
||||
action: "block",
|
||||
filters: ["dns"],
|
||||
traffic: wirefilterExpression,
|
||||
}),
|
||||
});
|
||||
|
||||
console.log("Created rule successfully");
|
||||
} catch (err) {
|
||||
console.error(`Error occurred while creating rule - ${err.toString()}`);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Deletes a Zero Trust rule.
|
||||
@@ -168,7 +174,14 @@ export const createZeroTrustRule = (wirefilterExpression) =>
|
||||
* @param {number} id The ID of the rule to be deleted.
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
export const deleteZeroTrustRule = (id) =>
|
||||
requestGateway(`/rules/${id}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
export const deleteZeroTrustRule = async (id) => {
|
||||
try {
|
||||
await requestGateway(`/rules/${id}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
|
||||
console.log("Deleted rule successfully");
|
||||
} catch (err) {
|
||||
console.error(`Error occurred while deleting rule - ${err.toString()}`);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user