1
0
Fork 0

Try handle case when configured instance domain is different than the actual instance domain

Honestly how do I even test if this will work
This commit is contained in:
Lim Chee Aun 2023-05-09 18:48:19 +08:00
parent ef12916bab
commit d264af14f1
2 changed files with 9 additions and 6 deletions

View file

@ -112,7 +112,7 @@ function App() {
const masto = initClient({ instance: instanceURL, accessToken });
await Promise.allSettled([
initInstance(masto),
initInstance(masto, instanceURL),
initAccount(masto, instanceURL, accessToken),
]);
initPreferences(masto);
@ -124,13 +124,13 @@ function App() {
const account = getCurrentAccount();
if (account) {
store.session.set('currentAccount', account.info.id);
const { masto } = api({ account });
const { masto, instance } = api({ account });
console.log('masto', masto);
initPreferences(masto);
setUIState('loading');
(async () => {
try {
await initInstance(masto);
await initInstance(masto, instance);
} catch (e) {
} finally {
setIsLoggedIn(true);

View file

@ -48,7 +48,7 @@ export function initClient({ instance, accessToken }) {
// Get the instance information
// The config is needed for composing
export async function initInstance(client) {
export async function initInstance(client, instance) {
const masto = client;
// Request v2, fallback to v1 if fail
let info;
@ -70,16 +70,19 @@ export async function initInstance(client) {
domain,
configuration: { urls: { streaming } = {} } = {},
} = info;
const instances = store.local.getJSON('instances') || {};
if (uri || domain) {
const instances = store.local.getJSON('instances') || {};
instances[
(domain || uri)
.replace(/^https?:\/\//, '')
.replace(/\/+$/, '')
.toLowerCase()
] = info;
store.local.setJSON('instances', instances);
}
if (instance) {
instances[instance.toLowerCase()] = info;
}
store.local.setJSON('instances', instances);
// This is a weird place to put this but here's updating the masto instance with the streaming API URL set in the configuration
// Reason: Streaming WebSocket URL may change, unlike the standard API REST URLs
if (streamingApi || streaming) {