mirror of
https://github.com/zoriya/flood.git
synced 2025-12-06 07:16:18 +00:00
server: replace domain from URL RegEx with plain split, slice and join
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import {domainName as matchDomainName} from '../../shared/util/regEx';
|
||||
|
||||
import type {TorrentProperties} from '../../shared/types/Torrent';
|
||||
|
||||
export const hasTorrentFinished = (
|
||||
@@ -22,31 +20,20 @@ export const hasTorrentFinished = (
|
||||
};
|
||||
|
||||
export const getDomainsFromURLs = (urls: Array<string>): Array<string> => {
|
||||
const domains: Array<string> = [];
|
||||
return [
|
||||
...urls.reduce((memo: Set<string>, url: string) => {
|
||||
const fqdn = url.split('/')[2]?.split(':')[0];
|
||||
|
||||
urls.forEach((url) => {
|
||||
const regexMatched = matchDomainName.exec(url);
|
||||
if (fqdn?.length > 0) {
|
||||
const domainLastParts = fqdn.split('.').slice(-2);
|
||||
|
||||
if (regexMatched != null && regexMatched[1]) {
|
||||
let domain = regexMatched[1];
|
||||
|
||||
const minSubsetLength = 3;
|
||||
const domainSubsets = domain.split('.');
|
||||
let desiredSubsets = 2;
|
||||
|
||||
if (domainSubsets.length > desiredSubsets) {
|
||||
const lastDesiredSubset = domainSubsets[domainSubsets.length - desiredSubsets];
|
||||
if (lastDesiredSubset.length <= minSubsetLength) {
|
||||
desiredSubsets += 1;
|
||||
// ignore IP addresses. RFC 952: first char of a valid TLD must be an alpha char
|
||||
if (!'0123456789'.includes(domainLastParts[domainLastParts.length - 1]?.[0])) {
|
||||
memo.add(domainLastParts.join('.'));
|
||||
}
|
||||
}
|
||||
|
||||
domain = domainSubsets.slice(desiredSubsets * -1).join('.');
|
||||
|
||||
domains.push(domain);
|
||||
}
|
||||
});
|
||||
|
||||
// Deduplicate
|
||||
return [...new Set(domains)];
|
||||
return memo;
|
||||
}, new Set()),
|
||||
];
|
||||
};
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export const url = /^(?:https?|ftp):\/\/.{1,}\.{1}.{1,}/;
|
||||
export const domainName = /(?:https?|udp):\/\/(?:www\.)?([-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,18}\b)*(\/[/\d\w.-]*)*(?:[?])*(.+)*/i;
|
||||
export const cdata = /<!\[CDATA\[(.*?)\]\]>/;
|
||||
export const noComma = /^[^,]+$/;
|
||||
|
||||
Reference in New Issue
Block a user