new api instance + api sorting fix
This commit is contained in:
parent
3294eaf2fa
commit
794696b770
2 changed files with 10 additions and 2 deletions
|
|
@ -54,6 +54,7 @@ export const apiSettings = {
|
||||||
console.error('Failed to load instances from GitHub:', error);
|
console.error('Failed to load instances from GitHub:', error);
|
||||||
this.defaultInstances = {
|
this.defaultInstances = {
|
||||||
api: [
|
api: [
|
||||||
|
'https://eu-central.monochrome.tf',
|
||||||
'https://us-west.monochrome.tf',
|
'https://us-west.monochrome.tf',
|
||||||
'https://arran.monochrome.tf',
|
'https://arran.monochrome.tf',
|
||||||
'https://api.monochrome.tf',
|
'https://api.monochrome.tf',
|
||||||
|
|
@ -180,7 +181,7 @@ export const apiSettings = {
|
||||||
return results;
|
return results;
|
||||||
},
|
},
|
||||||
|
|
||||||
async getInstances(type = 'api') {
|
async getInstances(type = 'api', sortBySpeed = false) {
|
||||||
let instancesObj;
|
let instancesObj;
|
||||||
|
|
||||||
const stored = localStorage.getItem(this.STORAGE_KEY);
|
const stored = localStorage.getItem(this.STORAGE_KEY);
|
||||||
|
|
@ -218,6 +219,12 @@ export const apiSettings = {
|
||||||
Object.assign(speedCache, this.getCachedSpeedTests());
|
Object.assign(speedCache, this.getCachedSpeedTests());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default: return instances in their stored/manual order (respects manual reordering)
|
||||||
|
// Only sort by speed when explicitly requested (e.g., refresh speed test)
|
||||||
|
if (!sortBySpeed) {
|
||||||
|
return targetUrls;
|
||||||
|
}
|
||||||
|
|
||||||
const sortList = (list) => {
|
const sortList = (list) => {
|
||||||
return [...list].sort((a, b) => {
|
return [...list].sort((a, b) => {
|
||||||
const speedA = speedCache.speeds[getCacheKey(a)]?.speed ?? Infinity;
|
const speedA = speedCache.speeds[getCacheKey(a)]?.speed ?? Infinity;
|
||||||
|
|
@ -253,7 +260,7 @@ export const apiSettings = {
|
||||||
this.updateSpeedCache(allResults);
|
this.updateSpeedCache(allResults);
|
||||||
|
|
||||||
// Return API instances for the UI to render (default view)
|
// Return API instances for the UI to render (default view)
|
||||||
return this.getInstances('api');
|
return this.getInstances('api', true);
|
||||||
},
|
},
|
||||||
saveInstances(instances, type) {
|
saveInstances(instances, type) {
|
||||||
if (type) {
|
if (type) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"api": [
|
"api": [
|
||||||
|
"https://eu-central.monochrome.tf",
|
||||||
"https://us-west.monochrome.tf",
|
"https://us-west.monochrome.tf",
|
||||||
"https://arran.monochrome.tf",
|
"https://arran.monochrome.tf",
|
||||||
"https://api.monochrome.tf/",
|
"https://api.monochrome.tf/",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue