Skip to content

Commit

Permalink
wip: add subpath ipfs link support too
Browse files Browse the repository at this point in the history
  • Loading branch information
umar-ahmed committed Sep 17, 2024
1 parent 20aaa85 commit e8a39ac
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/clean-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const cleanBlocklist = (config: Config): Config => {
// when cleaning the blocklist, we want to:
// - remove domains that are already present on the blocklist through an equal or less specific match
// - convert all unicode domains to punycode
// - find IPFS subdomain gateway links and store only the CIDs
// - find IPFS subdomain or subpath gateway links and store only the CIDs
// - remove duplicate entries

const blocklistSet = new Set(config.blacklist);
Expand All @@ -68,9 +68,15 @@ export const cleanBlocklist = (config: Config): Config => {
return punycodeDomain;
}).map(domain => {
// Extract CID from IPFS subdomain gateway links
const ipfsMatch = domain.match(/^(.+)\.ipfs\..+$/);
if (ipfsMatch) {
return ipfsMatch[1];
const ipfsSubdomainMatch = domain.match(/^(.+)\.ipfs\..+$/);
if (ipfsSubdomainMatch) {
return ipfsSubdomainMatch[1];
}

// Extract CID from IPFS subpath gateway links
const ipfsSubpathMatch = domain.match(/^.+\/ipfs\/([^\/]+).*$/);
if (ipfsSubpathMatch) {
return ipfsSubpathMatch[1];
}

return domain;
Expand Down

0 comments on commit e8a39ac

Please sign in to comment.