mirror of
https://github.com/Nezumi-2711/cloudflare-gateway-pihole-scripts.git
synced 2026-09-22 13:38:37 +00:00
Merge pull request #23 from hlqviet/refactor/domain-process
Domain process code refactor
This commit is contained in:
@@ -44,3 +44,22 @@ const request = async (url, options) => {
|
||||
*/
|
||||
export const requestGateway = (path, options) =>
|
||||
request(`${API_HOST}/accounts/${ACCOUNT_ID}/gateway${path}`, options);
|
||||
|
||||
/**
|
||||
* Normalizes a domain.
|
||||
* @param {string} value The value to be normalized.
|
||||
* @param {boolean} isAllowlisting Whether the value is to be whitelisted.
|
||||
* @returns {string}
|
||||
*/
|
||||
export const normalizeDomain = (value, isAllowlisting) => {
|
||||
const normalized = value
|
||||
.replace(/(0\.0\.0\.0|127\.0\.0\.1|::1|::)\s+/, "")
|
||||
.replace("||", "")
|
||||
.replace("^$important", "")
|
||||
.replace("*.", "")
|
||||
.replace("^", "");
|
||||
|
||||
if (isAllowlisting) return normalized.replace("@@||", "");
|
||||
|
||||
return normalized;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user