mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-02 14:16:39 +01:00
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:
parent
ef12916bab
commit
d264af14f1
2 changed files with 9 additions and 6 deletions
|
@ -112,7 +112,7 @@ function App() {
|
||||||
|
|
||||||
const masto = initClient({ instance: instanceURL, accessToken });
|
const masto = initClient({ instance: instanceURL, accessToken });
|
||||||
await Promise.allSettled([
|
await Promise.allSettled([
|
||||||
initInstance(masto),
|
initInstance(masto, instanceURL),
|
||||||
initAccount(masto, instanceURL, accessToken),
|
initAccount(masto, instanceURL, accessToken),
|
||||||
]);
|
]);
|
||||||
initPreferences(masto);
|
initPreferences(masto);
|
||||||
|
@ -124,13 +124,13 @@ function App() {
|
||||||
const account = getCurrentAccount();
|
const account = getCurrentAccount();
|
||||||
if (account) {
|
if (account) {
|
||||||
store.session.set('currentAccount', account.info.id);
|
store.session.set('currentAccount', account.info.id);
|
||||||
const { masto } = api({ account });
|
const { masto, instance } = api({ account });
|
||||||
console.log('masto', masto);
|
console.log('masto', masto);
|
||||||
initPreferences(masto);
|
initPreferences(masto);
|
||||||
setUIState('loading');
|
setUIState('loading');
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
await initInstance(masto);
|
await initInstance(masto, instance);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoggedIn(true);
|
setIsLoggedIn(true);
|
||||||
|
|
|
@ -48,7 +48,7 @@ export function initClient({ instance, accessToken }) {
|
||||||
|
|
||||||
// Get the instance information
|
// Get the instance information
|
||||||
// The config is needed for composing
|
// The config is needed for composing
|
||||||
export async function initInstance(client) {
|
export async function initInstance(client, instance) {
|
||||||
const masto = client;
|
const masto = client;
|
||||||
// Request v2, fallback to v1 if fail
|
// Request v2, fallback to v1 if fail
|
||||||
let info;
|
let info;
|
||||||
|
@ -70,16 +70,19 @@ export async function initInstance(client) {
|
||||||
domain,
|
domain,
|
||||||
configuration: { urls: { streaming } = {} } = {},
|
configuration: { urls: { streaming } = {} } = {},
|
||||||
} = info;
|
} = info;
|
||||||
|
const instances = store.local.getJSON('instances') || {};
|
||||||
if (uri || domain) {
|
if (uri || domain) {
|
||||||
const instances = store.local.getJSON('instances') || {};
|
|
||||||
instances[
|
instances[
|
||||||
(domain || uri)
|
(domain || uri)
|
||||||
.replace(/^https?:\/\//, '')
|
.replace(/^https?:\/\//, '')
|
||||||
.replace(/\/+$/, '')
|
.replace(/\/+$/, '')
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
] = info;
|
] = 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
|
// 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
|
// Reason: Streaming WebSocket URL may change, unlike the standard API REST URLs
|
||||||
if (streamingApi || streaming) {
|
if (streamingApi || streaming) {
|
||||||
|
|
Loading…
Reference in a new issue