mirror of
https://github.com/Nezumi-2711/cloudflare-gateway-pihole-scripts.git
synced 2026-09-22 13:38:37 +00:00
ported list download code to JS
This commit is contained in:
+2
-2
@@ -9,8 +9,8 @@ lerna-debug.log*
|
|||||||
|
|
||||||
# CGPS
|
# CGPS
|
||||||
output
|
output
|
||||||
input.csv
|
blocklist.txt
|
||||||
whitelist.csv
|
allowlist.txt
|
||||||
|
|
||||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
|
|||||||
+2
-2
@@ -18,8 +18,8 @@ import {
|
|||||||
readFile,
|
readFile,
|
||||||
} from "./lib/utils.js";
|
} from "./lib/utils.js";
|
||||||
|
|
||||||
const allowlistFilename = "whitelist.csv";
|
const allowlistFilename = "allowlist.txt";
|
||||||
const blocklistFilename = "input.csv";
|
const blocklistFilename = "blocklist.txt";
|
||||||
const allowlist = new Map();
|
const allowlist = new Map();
|
||||||
const blocklist = new Map();
|
const blocklist = new Map();
|
||||||
const domains = [];
|
const domains = [];
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { resolve } from "path";
|
||||||
|
|
||||||
|
import { downloadFiles } from "./lib/utils.js";
|
||||||
|
|
||||||
|
downloadFiles(resolve(process.argv[2]), process.argv.slice(3));
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
source $(dirname "$0")/lib/helpers.sh
|
|
||||||
|
|
||||||
# declare an array of urls
|
# declare an array of urls
|
||||||
urls=(
|
urls=(
|
||||||
https://raw.githubusercontent.com/mullvad/dns-blocklists/main/output/doh/doh_adblock.txt
|
https://raw.githubusercontent.com/mullvad/dns-blocklists/main/output/doh/doh_adblock.txt
|
||||||
@@ -13,7 +11,7 @@ urls=(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# download all files in parallel and append them to input.csv
|
# download all files in parallel and append them to input.csv
|
||||||
download_lists $urls 'input.csv'
|
node download_files.js blocklist.txt ${urls[@]}
|
||||||
|
|
||||||
# print a message when done
|
# print a message when done
|
||||||
echo "Done. The input.csv file contains merged data from recommended filter lists."
|
echo "Done. The blocklist.txt file contains merged data from recommended filter lists."
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
# Use the provided lists or add your own.
|
# Use the provided lists or add your own.
|
||||||
# There is no limit on the amount of whitelisted domains you can have.
|
# There is no limit on the amount of whitelisted domains you can have.
|
||||||
|
|
||||||
source $(dirname "$0")/lib/helpers.sh
|
|
||||||
|
|
||||||
# declare an array of urls
|
# declare an array of urls
|
||||||
urls=(
|
urls=(
|
||||||
https://raw.githubusercontent.com/im-sm/Pi-hole-Torrent-Blocklist/main/all-torrent-trackres.txt
|
https://raw.githubusercontent.com/im-sm/Pi-hole-Torrent-Blocklist/main/all-torrent-trackres.txt
|
||||||
@@ -36,7 +34,7 @@ urls=(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# download all files in parallel and append them to whitelist.csv
|
# download all files in parallel and append them to whitelist.csv
|
||||||
download_lists $urls 'whitelist.csv'
|
node download_files.js allowlist.txt ${urls[@]}
|
||||||
|
|
||||||
# print a message when done
|
# print a message when done
|
||||||
echo "Done. The whitelist.csv file contains merged data from recommended whitelists."
|
echo "Done. The allowlist.txt file contains merged data from recommended whitelists."
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
download_lists() {
|
|
||||||
urls=$1
|
|
||||||
output=$2
|
|
||||||
|
|
||||||
curl -sSfL --parallel --parallel-max 10 --retry 3 ${urls[@]} > $output
|
|
||||||
}
|
|
||||||
+28
-1
@@ -1,7 +1,12 @@
|
|||||||
import { once } from "events";
|
import { once } from "events";
|
||||||
import { createReadStream } from "fs";
|
import { createReadStream, createWriteStream } from "fs";
|
||||||
import { basename } from "path";
|
import { basename } from "path";
|
||||||
import { createInterface } from "readline";
|
import { createInterface } from "readline";
|
||||||
|
import { WritableStream } from "stream/web";
|
||||||
|
|
||||||
|
if (!globalThis.fetch) {
|
||||||
|
globalThis.fetch = (await import("node-fetch")).default;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sleeps for a specified amount of time.
|
* Sleeps for a specified amount of time.
|
||||||
@@ -46,6 +51,28 @@ export const isComment = (value) =>
|
|||||||
value.startsWith("/*") ||
|
value.startsWith("/*") ||
|
||||||
value.startsWith("*/");
|
value.startsWith("*/");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downloads files and concatenates them into one file.
|
||||||
|
* @param {string} filePath The path to the file being written to.
|
||||||
|
* @param {string[]} urls The URLs to the files to be downloaded.
|
||||||
|
*/
|
||||||
|
export const downloadFiles = async (filePath, urls) => {
|
||||||
|
const writeStream = createWriteStream(filePath, { flags: "a" });
|
||||||
|
const writableStream = new WritableStream({
|
||||||
|
write(chunk) {
|
||||||
|
writeStream.write(chunk);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const responses = await Promise.all(urls.map((url) => fetch(url)));
|
||||||
|
|
||||||
|
for (const response of responses) {
|
||||||
|
await response.body?.pipeTo(writableStream, { preventClose: true });
|
||||||
|
writeStream.write("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
await writableStream.close();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @callback onLine
|
* @callback onLine
|
||||||
* @param {string} line The current line.
|
* @param {string} line The current line.
|
||||||
|
|||||||
Reference in New Issue
Block a user