-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathurlSource.js
More file actions
28 lines (24 loc) · 867 Bytes
/
urlSource.js
File metadata and controls
28 lines (24 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// @ts-check
import { readFile } from "fs/promises";
/**
* Downloads the list of LDES streams endpoints.
* @returns {Promise<Array<{url: string, title: string}>>} The array of endpoint URLs with their titles.
*/
export const getEndpointUrls = async () => {
const response = await fetch(
"https://raw.githubusercontent.com/imec-int/ldes-registry/main/urls.txt"
);
const data = await response.text();
//const data = await readFile("./test.txt", { encoding: "utf-8" });
return data
.split("\n")
.filter((url) => url.length > 0)
.map((urlWithTitle) => {
const parts = urlWithTitle.split(",");
// title fallback is the url itself
let item = { url: parts[0], title: parts[1] || parts[0] };
// trim and replace all " with empty string
item.url = item.url.trim().replace(/"/g, "");
return item;
});
};