mirror of
https://github.com/unraid/api.git
synced 2026-05-05 14:41:54 -05:00
feat: use local server data for /servers when in anon mode
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user