mirror of
https://github.com/unraid/api.git
synced 2025-12-31 13:39:52 -06:00
feat: secondary changes
This commit is contained in:
@@ -62,12 +62,12 @@ export const getCloudData = async (
|
|||||||
|
|
||||||
export const getServersData = async ({
|
export const getServersData = async ({
|
||||||
client,
|
client,
|
||||||
v,
|
verbosity,
|
||||||
}: {
|
}: {
|
||||||
client: ApolloClient<NormalizedCacheObject>;
|
client: ApolloClient<NormalizedCacheObject>;
|
||||||
v: number;
|
verbosity: number;
|
||||||
}): Promise<ServersPayload | null> => {
|
}): Promise<ServersPayload | null> => {
|
||||||
if (v === 0) {
|
if (verbosity === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,6 +201,12 @@ export class ReportCommand extends CommandRunner {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private defaultOptions: ReportOptions = {
|
||||||
|
raw: false,
|
||||||
|
json: false,
|
||||||
|
verbose: 0,
|
||||||
|
};
|
||||||
|
|
||||||
@Option({
|
@Option({
|
||||||
flags: '-r, --raw',
|
flags: '-r, --raw',
|
||||||
description: 'whether to enable raw command output',
|
description: 'whether to enable raw command output',
|
||||||
@@ -236,7 +242,7 @@ export class ReportCommand extends CommandRunner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async report(options?: ReportOptions): Promise<string | ReportObject | void> {
|
async report(options: ReportOptions = this.defaultOptions): Promise<string | ReportObject | void> {
|
||||||
// Check if we have a tty attached to stdout
|
// Check if we have a tty attached to stdout
|
||||||
// If we don't then this is being piped to a log file, etc.
|
// If we don't then this is being piped to a log file, etc.
|
||||||
const hasTty = process.stdout.isTTY;
|
const hasTty = process.stdout.isTTY;
|
||||||
@@ -245,7 +251,7 @@ export class ReportCommand extends CommandRunner {
|
|||||||
// If this has a tty it's interactive
|
// If this has a tty it's interactive
|
||||||
// AND
|
// AND
|
||||||
// If they don't have --raw
|
// If they don't have --raw
|
||||||
const isInteractive = hasTty && !options?.raw;
|
const isInteractive = hasTty && !options.raw;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Show loading message
|
// Show loading message
|
||||||
@@ -254,7 +260,6 @@ export class ReportCommand extends CommandRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const jsonReport = options?.json ?? false;
|
const jsonReport = options?.json ?? false;
|
||||||
const v = options?.verbose ?? 0;
|
|
||||||
|
|
||||||
// Find all processes called "unraid-api" which aren't this process
|
// Find all processes called "unraid-api" which aren't this process
|
||||||
const unraidApiRunning = await isUnraidApiRunning();
|
const unraidApiRunning = await isUnraidApiRunning();
|
||||||
@@ -282,7 +287,7 @@ export class ReportCommand extends CommandRunner {
|
|||||||
|
|
||||||
// Query local graphql using upc's API key
|
// Query local graphql using upc's API key
|
||||||
// Get the servers array
|
// Get the servers array
|
||||||
const servers = await getServersData({ client, v });
|
const servers = await getServersData({ client, verbosity: options.verbose });
|
||||||
|
|
||||||
// Check if the API key is valid
|
// Check if the API key is valid
|
||||||
const isApiKeyValid = cloud?.apiKey.valid ?? false;
|
const isApiKeyValid = cloud?.apiKey.valid ?? false;
|
||||||
@@ -322,8 +327,8 @@ export class ReportCommand extends CommandRunner {
|
|||||||
status: cloud?.cloud.status ?? 'error',
|
status: cloud?.cloud.status ?? 'error',
|
||||||
...(cloud?.cloud.error ? { error: cloud.cloud.error } : {}),
|
...(cloud?.cloud.error ? { error: cloud.cloud.error } : {}),
|
||||||
...(cloud?.cloud.status === 'ok' ? { ip: cloud.cloud.ip ?? 'NO_IP' } : {}),
|
...(cloud?.cloud.status === 'ok' ? { ip: cloud.cloud.ip ?? 'NO_IP' } : {}),
|
||||||
...(getAllowedOrigins(cloud, v)
|
...(getAllowedOrigins(cloud, options.verbose)
|
||||||
? { allowedOrigins: getAllowedOrigins(cloud, v) }
|
? { allowedOrigins: getAllowedOrigins(cloud, options.verbose) }
|
||||||
: {}),
|
: {}),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -347,10 +352,10 @@ MY_SERVERS: ${reportObject.myServers.status}${
|
|||||||
? `\nMY_SERVERS_USERNAME: ${reportObject.myServers.myServersUsername}`
|
? `\nMY_SERVERS_USERNAME: ${reportObject.myServers.myServersUsername}`
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
CLOUD: ${getReadableCloudDetails(reportObject, v)}
|
CLOUD: ${getReadableCloudDetails(reportObject, options.verbose)}
|
||||||
MINI-GRAPH: ${getReadableMinigraphDetails(reportObject)}${getReadableServerDetails(
|
MINI-GRAPH: ${getReadableMinigraphDetails(reportObject)}${getReadableServerDetails(
|
||||||
reportObject,
|
reportObject,
|
||||||
v
|
options.verbose
|
||||||
)}${getReadableAllowedOrigins(reportObject)}
|
)}${getReadableAllowedOrigins(reportObject)}
|
||||||
</----UNRAID-API-REPORT----->
|
</----UNRAID-API-REPORT----->
|
||||||
`;
|
`;
|
||||||
|
|||||||
Reference in New Issue
Block a user