alt-fetch: append the path after selecting the endpoints (fixes #55)

merge-requests/14/merge
Michał 'rysiek' Woźniak 2022-06-22 20:42:22 +00:00
rodzic 6bef03ef0b
commit fcb02ade52
1 zmienionych plików z 7 dodań i 2 usunięć

Wyświetl plik

@ -79,18 +79,23 @@
// if we have fewer than the configured concurrency or just as many, use all of them
if (sourceEndpoints.length <= config.concurrency) {
var useEndpoints = sourceEndpoints
// otherwise get `config.concurrency` endpoints at random
} else {
var useEndpoints = new Array()
while (useEndpoints.length < config.concurrency) {
// put in the address while we're at it
useEndpoints.push(
sourceEndpoints
.splice(Math.floor(Math.random() * sourceEndpoints.length), 1)[0] + path
.splice(Math.floor(Math.random() * sourceEndpoints.length), 1)[0]
)
}
}
// add the rest of the path to each endpoint
useEndpoints.forEach((endpoint, index) => {
useEndpoints[index] = endpoint + path;
});
// debug log
LR.log(pluginName, `fetching from alternative endpoints:\n ${useEndpoints.join('\n ')}`)