mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-11 03:59:09 +00:00
25 lines
683 B
TypeScript
25 lines
683 B
TypeScript
export function extractValidDownloadUrls(text: string): string[] {
|
|
const lines = text.split('\n');
|
|
const urls: string[] = [];
|
|
|
|
for (const line of lines) {
|
|
const trimmed = line.trim();
|
|
if (!trimmed) continue;
|
|
|
|
// Split by whitespace in case multiple URLs are on one line
|
|
const parts = trimmed.split(/\s+/);
|
|
for (const part of parts) {
|
|
try {
|
|
const url = new URL(part);
|
|
if (url.protocol === 'http:' || url.protocol === 'https:' || url.protocol === 'ftp:' || url.protocol === 'sftp:') {
|
|
urls.push(url.toString());
|
|
}
|
|
} catch (e) {
|
|
// Not a valid URL
|
|
}
|
|
}
|
|
}
|
|
|
|
return [...new Set(urls)];
|
|
}
|