fix: unwrap [{data:[...]}] wrapper in server webhook response parsing

The new webhook wraps data in an outer array: [{data: [...]}].
The old parsing only handled {data: [...]} directly, so .data was
undefined and the server list ended up empty — causing the location
to fall through to the slugified default.
This commit is contained in:
Oliver
2026-06-15 12:17:40 -03:00
parent 4fe11e124a
commit e0b66ae824
2 changed files with 14 additions and 4 deletions
+7 -2
View File
@@ -649,8 +649,13 @@ async function initServerLocations() {
try {
const res = await fetch(SERVER_WEBHOOK);
const raw = await res.json();
// Handle both {data: [...]} and flat array/object
const list = raw && Array.isArray(raw.data) ? raw.data : Array.isArray(raw) ? raw : [raw].filter(Boolean);
// Unwrap [{data: [...]}] → {data: [...]}
let data = raw;
if (Array.isArray(raw) && raw.length > 0 && raw[0] && Array.isArray(raw[0].data)) {
data = raw[0];
}
// Handle {data: [...]}, flat array, or single object
const list = data && Array.isArray(data.data) ? data.data : Array.isArray(data) ? data : [data].filter(Boolean);
const servers = list.filter(function (s) { return s && s.server; });
// Clear existing options