mirror of
https://github.com/Nezumi-2711/cloudflare-gateway-pihole-scripts.git
synced 2026-09-22 13:38:37 +00:00
Merge pull request #35 from hlqviet/feat/npm-scripts
Add npm scripts for convenience
This commit is contained in:
@@ -33,20 +33,18 @@ jobs:
|
|||||||
- name: Install npm dependencies
|
- name: Install npm dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
|
|
||||||
- name: Download recommended whitelist
|
- name: Download allowlists
|
||||||
run: bash ./get_recommended_whitelist.sh
|
run: npm run download:allowlist
|
||||||
env:
|
env:
|
||||||
ALLOWLIST_URLS: ${{ vars.ALLOWLIST_URLS }}
|
ALLOWLIST_URLS: ${{ vars.ALLOWLIST_URLS }}
|
||||||
|
|
||||||
- name: Download recommended filters
|
- name: Download blocklists
|
||||||
run: bash ./get_recommended_filters.sh
|
run: npm run download:blocklist
|
||||||
env:
|
env:
|
||||||
BLOCKLIST_URLS: ${{ vars.BLOCKLIST_URLS }}
|
BLOCKLIST_URLS: ${{ vars.BLOCKLIST_URLS }}
|
||||||
|
|
||||||
- name: Delete old rules and lists
|
- name: Delete old rules and lists
|
||||||
run: |
|
run: npm run cloudflare-delete
|
||||||
node cf_gateway_rule_delete.js
|
|
||||||
node cf_list_delete.js
|
|
||||||
env:
|
env:
|
||||||
CLOUDFLARE_API_KEY: ${{ secrets.CLOUDFLARE_API_KEY }}
|
CLOUDFLARE_API_KEY: ${{ secrets.CLOUDFLARE_API_KEY }}
|
||||||
CLOUDFLARE_ACCOUNT_EMAIL: ${{ secrets.CLOUDFLARE_ACCOUNT_EMAIL }}
|
CLOUDFLARE_ACCOUNT_EMAIL: ${{ secrets.CLOUDFLARE_ACCOUNT_EMAIL }}
|
||||||
@@ -55,9 +53,7 @@ jobs:
|
|||||||
FAST_MODE: ${{ vars.FAST_MODE }}
|
FAST_MODE: ${{ vars.FAST_MODE }}
|
||||||
|
|
||||||
- name: Create new rules and lists
|
- name: Create new rules and lists
|
||||||
run: |
|
run: npm run cloudflare-create
|
||||||
node cf_list_create.js
|
|
||||||
node cf_gateway_rule_create.js
|
|
||||||
env:
|
env:
|
||||||
CLOUDFLARE_API_KEY: ${{ secrets.CLOUDFLARE_API_KEY }}
|
CLOUDFLARE_API_KEY: ${{ secrets.CLOUDFLARE_API_KEY }}
|
||||||
CLOUDFLARE_ACCOUNT_EMAIL: ${{ secrets.CLOUDFLARE_ACCOUNT_EMAIL }}
|
CLOUDFLARE_ACCOUNT_EMAIL: ${{ secrets.CLOUDFLARE_ACCOUNT_EMAIL }}
|
||||||
|
|||||||
+1
-3
@@ -125,9 +125,7 @@ console.log(`Number of unnecessary domains: ${unnecessaryDomainCount}`);
|
|||||||
console.log(`Number of blocked domains: ${domains.length}`);
|
console.log(`Number of blocked domains: ${domains.length}`);
|
||||||
console.log(`Number of allowed domains: ${allowedDomainCount}`);
|
console.log(`Number of allowed domains: ${allowedDomainCount}`);
|
||||||
console.log(
|
console.log(
|
||||||
`Number of lists which will be created: ${Math.ceil(
|
`Number of lists to be created: ${Math.ceil(domains.length / LIST_ITEM_SIZE)}`
|
||||||
domains.length / LIST_ITEM_SIZE
|
|
||||||
)}`
|
|
||||||
);
|
);
|
||||||
console.log("\n\n");
|
console.log("\n\n");
|
||||||
|
|
||||||
|
|||||||
+24
-10
@@ -1,3 +1,5 @@
|
|||||||
|
import { existsSync } from "fs";
|
||||||
|
import { unlink } from "fs/promises";
|
||||||
import { resolve } from "path";
|
import { resolve } from "path";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -15,16 +17,28 @@ const blocklistUrls = USER_DEFINED_BLOCKLIST_URLS || RECOMMENDED_BLOCKLIST_URLS;
|
|||||||
const listType = process.argv[2];
|
const listType = process.argv[2];
|
||||||
|
|
||||||
const downloadLists = async (filename, urls) => {
|
const downloadLists = async (filename, urls) => {
|
||||||
await downloadFiles(resolve(`./${filename}`), urls);
|
const filePath = resolve(`./${filename}`);
|
||||||
console.log(
|
|
||||||
`Done. The ${filename} file contains merged data from the following list(s):`
|
if (existsSync(filePath)) {
|
||||||
);
|
await unlink(filePath);
|
||||||
console.log(
|
}
|
||||||
urls.reduce(
|
|
||||||
(previous, current, index) => previous + `${index + 1}. ${current}\n`,
|
try {
|
||||||
""
|
await downloadFiles(filePath, urls);
|
||||||
)
|
|
||||||
);
|
console.log(
|
||||||
|
`Done. The ${filename} file contains merged data from the following list(s):`
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
urls.reduce(
|
||||||
|
(previous, current, index) => previous + `${index + 1}. ${current}\n`,
|
||||||
|
""
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`An error occurred while processing ${filename}:\n`, err);
|
||||||
|
console.error("URLs:\n", urls);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (listType) {
|
switch (listType) {
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ if (!globalThis.fetch) {
|
|||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
const request = async (url, options) => {
|
const request = async (url, options) => {
|
||||||
|
if (!API_TOKEN || !ACCOUNT_ID || !ACCOUNT_EMAIL) {
|
||||||
|
throw new Error(
|
||||||
|
"One or more required secrets have not been added: CLOUDFLARE_API_KEY, CLOUDFLARE_ACCOUNT_ID, and CLOUDFLARE_ACCOUNT_EMAIL"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${API_TOKEN}`,
|
Authorization: `Bearer ${API_TOKEN}`,
|
||||||
|
|||||||
@@ -1,4 +1,17 @@
|
|||||||
{
|
{
|
||||||
|
"scripts": {
|
||||||
|
"start": "npm run download && npm run cloudflare-delete && npm run cloudflare-create",
|
||||||
|
"dry": "npm run download && DRY_RUN=1 npm run cloudflare-create:list",
|
||||||
|
"download": "node download_lists.js",
|
||||||
|
"download:allowlist": "node download_lists.js allowlist",
|
||||||
|
"download:blocklist": "node download_lists.js blocklist",
|
||||||
|
"cloudflare-create": "npm run cloudflare-create:list && npm run cloudflare-create:rule",
|
||||||
|
"cloudflare-delete": "npm run cloudflare-delete:rule && npm run cloudflare-delete:list",
|
||||||
|
"cloudflare-create:rule": "node cf_gateway_rule_create.js",
|
||||||
|
"cloudflare-create:list": "node cf_list_create.js",
|
||||||
|
"cloudflare-delete:rule": "node cf_gateway_rule_delete.js",
|
||||||
|
"cloudflare-delete:list": "node cf_list_delete.js"
|
||||||
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
|
|||||||
Reference in New Issue
Block a user