feat: use local server data for /servers when in anon mode

This commit is contained in:
Alexis
2021-09-09 08:24:16 +09:30
parent a474cc743e
commit 34da448f1e
2 changed files with 18 additions and 5 deletions
+14 -1
View File
@@ -3,10 +3,11 @@
* Written by: Alexis Tyler
*/
import { pubsub, utils, errors, states, apiManager, graphqlLogger } from '../../core';
import { pubsub, utils, errors, states, apiManager, graphqlLogger, paths } from '../../core';
import { hasSubscribedToChannel } from '../../ws';
import { userCache, CachedServer, CachedServers } from '../../cache';
import { getServers as getUserServers } from '../../utils';
import { loadState } from '../../core/utils/misc/load-state';
const { varState, networkState } = states;
@@ -92,6 +93,18 @@ export const getServers = async (): Promise<Server[]> => {
// No cached servers found
if (!cachedServers) {
// Get my server's config file path
const configPath = paths.get('myservers-config')!;
const myserversConfigFile = loadState<{
remote: { anonMode?: string };
}>(configPath);
// If they're in anon mode bail
if (myserversConfigFile.remote.anonMode !== undefined) {
graphqlLogger.debug('Falling back to local state for /servers endpoint');
return getLocalServer(apiKey);
}
// Fetch servers from mothership
const servers = await getUserServers(apiKey);
+4 -4
View File
@@ -33,12 +33,12 @@ export const startInternal = (apiKey: string) => {
}
}));
const myserversConfigFile = loadState<{
remote: { anonMode?: string };
}>(configPath);
// Internal is ready at this point
if (!sockets.relay) {
const myserversConfigFile = loadState<{
remote: { anonMode?: string };
}>(configPath);
// If they're in anon mode bail
if (myserversConfigFile.remote.anonMode !== undefined) {
return;