Allow addition of denySub entries (#4223)

* Allow addition of denySub entries

* Section does exist (now)

* s/twitter.com/x.com/
This commit is contained in:
Jaco
2024-01-22 15:35:17 +02:00
committed by GitHub
parent 649af44df3
commit 46c08c0c49
2 changed files with 27 additions and 13 deletions
+3
View File
@@ -28860,5 +28860,8 @@
"zwalletconnect.com", "zwalletconnect.com",
"zxcoin.website", "zxcoin.website",
"zzcoin.website" "zzcoin.website"
],
"denySub": [
"x.com/jacogr"
] ]
} }
+24 -13
View File
@@ -6,29 +6,35 @@ import fs from 'node:fs';
// @ts-expect-error @polkadot/dev scripts don't have .d.ts files // @ts-expect-error @polkadot/dev scripts don't have .d.ts files
import { mkdirpSync, rimrafSync } from '@polkadot/dev/scripts/util.mjs'; import { mkdirpSync, rimrafSync } from '@polkadot/dev/scripts/util.mjs';
/** @typedef {{ allow: string[]; deny: string[]; }} AllList */ /** @typedef {{ allow: string[]; deny: string[]; denySub: string[] }} AllList */
const KNOWN_URLS = ['telegra.ph', 'twitter.com', 'youtube.com']; const KNOWN_URLS = ['telegra.ph', 'twitter.com', 'youtube.com', 'x.com'];
/** /**
* @param {string} url * @param {string} url
* @param {boolean} [allowSub]
* @returns {string} * @returns {string}
*/ */
function sanitizeUrl (url) { function sanitizeUrl (url, allowSub) {
return ( const naked = url.includes('://')
url.includes('://') ? url.split('://')[1]
? url.split('://')[1] : url;
: url
).split('/')[0]; return allowSub
// return without trailing /
? naked.split('/').filter((p) => !!p).join('/')
// return without subdomain
: naked.split('/')[0];
} }
/** /**
* @param {string[]} list * @param {string[]} list
* @param {boolean} [allowSub]
* @returns {string[]} * @returns {string[]}
*/ */
function filterSection (list) { function filterSection (list, allowSub) {
return list return list
.map((entry) => sanitizeUrl(entry)) .map((entry) => sanitizeUrl(entry, allowSub))
.reduce((/** @type {string[]} */ filtered, entry) => { .reduce((/** @type {string[]} */ filtered, entry) => {
!filtered.includes(entry) && !filtered.includes(entry) &&
filtered.push(entry); filtered.push(entry);
@@ -39,10 +45,11 @@ function filterSection (list) {
/** /**
* @param {string[]} list * @param {string[]} list
* @param {boolean} [allowSub]
* @returns {string[]} * @returns {string[]}
*/ */
function sortSection (list) { function sortSection (list, allowSub) {
return filterSection(list).sort((a, b) => a.localeCompare(b)); return filterSection(list, allowSub).sort((a, b) => a.localeCompare(b));
} }
/** /**
@@ -222,7 +229,11 @@ const addr = readJson('address.json');
const all = readJson('all.json'); const all = readJson('all.json');
const meta = readMeta(); const meta = readMeta();
const deny = sortSection(addSites(all, addr)); const deny = sortSection(addSites(all, addr));
const allJson = { allow: sortSection(all.allow), deny: rewriteSubs(deny) }; const allJson = {
allow: sortSection(all.allow),
deny: rewriteSubs(deny),
denySub: sortSection(all.denySub, true)
};
// rewrite with all our entries (newline included) // rewrite with all our entries (newline included)
writeJson('address.json', sortAddresses(addr)); writeJson('address.json', sortAddresses(addr));