From 7c6157d47c76bfcccfefb5476b070a9c459e5b6e Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Fri, 27 Jan 2023 11:45:38 +0800 Subject: [PATCH] Try get the v2 instance config then fallback to v1 There are new things in v2 that will be needed later --- src/app.jsx | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/app.jsx b/src/app.jsx index 2e5d0083..8dd1c783 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -170,12 +170,24 @@ function App() { // Collect instance info (async () => { - const info = await masto.v1.instances.fetch(); + // Request v2, fallback to v1 if fail + let info; + try { + info = await masto.v2.instance.fetch(); + } catch (e) {} + if (!info) { + try { + info = await masto.v1.instances.fetch(); + } catch (e) {} + } + if (!info) return; console.log(info); const { uri, domain } = info; - const instances = store.local.getJSON('instances') || {}; - instances[(domain || uri).toLowerCase()] = info; - store.local.setJSON('instances', instances); + if (uri || domain) { + const instances = store.local.getJSON('instances') || {}; + instances[(domain || uri).toLowerCase()] = info; + store.local.setJSON('instances', instances); + } })(); }); states.init = true;