weights
This commit is contained in:
parent
b2241cecd9
commit
b962853b69
1 changed files with 18 additions and 4 deletions
|
|
@ -58,8 +58,8 @@ export const apiSettings = {
|
||||||
let data = null;
|
let data = null;
|
||||||
let fetchError = null;
|
let fetchError = null;
|
||||||
|
|
||||||
// Shuffle URLs to pick a random one first
|
// Prefer first URL, only try others as fallback
|
||||||
const urls = [...this.INSTANCES_URLS].sort(() => Math.random() - 0.5);
|
const urls = [...this.INSTANCES_URLS];
|
||||||
|
|
||||||
for (const url of urls) {
|
for (const url of urls) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -200,12 +200,26 @@ export const apiSettings = {
|
||||||
return array;
|
return array;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const prioritySort = (array) => {
|
||||||
|
const getUrl = (item) => (typeof item === 'string' ? item : item.url || '');
|
||||||
|
const top = [];
|
||||||
|
const middle = [];
|
||||||
|
const bottom = [];
|
||||||
|
for (const item of array) {
|
||||||
|
const url = getUrl(item);
|
||||||
|
if (url.includes('hifi.geeked.wtf')) top.push(item);
|
||||||
|
else if (url.includes('.qqdl.site')) bottom.push(item);
|
||||||
|
else middle.push(item);
|
||||||
|
}
|
||||||
|
return [...top, ...shuffle(middle), ...shuffle(bottom)];
|
||||||
|
};
|
||||||
|
|
||||||
if (instances.api && instances.api.length) {
|
if (instances.api && instances.api.length) {
|
||||||
instances.api = shuffle([...instances.api]);
|
instances.api = prioritySort([...instances.api]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instances.streaming && instances.streaming.length) {
|
if (instances.streaming && instances.streaming.length) {
|
||||||
instances.streaming = shuffle([...instances.streaming]);
|
instances.streaming = prioritySort([...instances.streaming]);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.saveInstances(instances);
|
this.saveInstances(instances);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue