Skip to content

High performance self-hosted photo and video management solution.

feat(cli): better server info output (#8307)

Jason Rasmussen613b544bf0eb
diff --git a/cli/src/commands/server-info.ts b/cli/src/commands/server-info.ts
index a7de804df9..074513bd61 100644
--- a/cli/src/commands/server-info.ts
+++ b/cli/src/commands/server-info.ts
@@ -1,15 +1,24 @@
-import { getAssetStatistics, getServerVersion, getSupportedMediaTypes } from '@immich/sdk';
+import { getAssetStatistics, getMyUserInfo, getServerVersion, getSupportedMediaTypes } from '@immich/sdk';
import { BaseOptions, authenticate } from 'src/utils';
export const serverInfo = async (options: BaseOptions) => {
- await authenticate(options);
+ const { url } = await authenticate(options);
- const versionInfo = await getServerVersion();
- const mediaTypes = await getSupportedMediaTypes();
- const stats = await getAssetStatistics({});
+ const [versionInfo, mediaTypes, stats, userInfo] = await Promise.all([
+ getServerVersion(),
+ getSupportedMediaTypes(),
+ getAssetStatistics({}),
+ getMyUserInfo(),
+ ]);
- console.log(`Server Version: ${versionInfo.major}.${versionInfo.minor}.${versionInfo.patch}`);
- console.log(`Image Types: ${mediaTypes.image.map((extension) => extension.replace('.', ''))}`);
- console.log(`Video Types: ${mediaTypes.video.map((extension) => extension.replace('.', ''))}`);
- console.log(`Statistics:\n Images: ${stats.images}\n Videos: ${stats.videos}\n Total: ${stats.total}`);
+ console.log(`Server Info (via ${userInfo.email})`);
+ console.log(` Url: ${url}`);
+ console.log(` Version: ${versionInfo.major}.${versionInfo.minor}.${versionInfo.patch}`);
+ console.log(` Formats:`);
+ console.log(` Images: ${mediaTypes.image.map((extension) => extension.replace('.', ''))}`);
+ console.log(` Videos: ${mediaTypes.video.map((extension) => extension.replace('.', ''))}`);
+ console.log(` Statistics:`);
+ console.log(` Images: ${stats.images}`);
+ console.log(` Videos: ${stats.videos}`);
+ console.log(` Total: ${stats.total}`);
};
diff --git a/cli/src/utils.ts b/cli/src/utils.ts
index c17ad69038..b2d34bbb48 100644
--- a/cli/src/utils.ts
+++ b/cli/src/utils.ts
@@ -15,21 +15,25 @@ export interface BaseOptions {
export type AuthDto = { url: string; key: string };
type OldAuthDto = { instanceUrl: string; apiKey: string };
-export const authenticate = async (options: BaseOptions): Promise<void> => {
+export const authenticate = async (options: BaseOptions): Promise<AuthDto> => {
const { configDirectory: configDir, url, key } = options;
// provided in command
if (url && key) {
- await connect(url, key);
- return;
+ return connect(url, key);
}
// fallback to auth file
const config = await readAuthFile(configDir);
- await connect(config.url, config.key);
+ const auth = await connect(config.url, config.key);
+ if (auth.url !== config.url) {
+ await writeAuthFile(configDir, auth);
+ }
+
+ return auth;
};
-export const connect = async (url: string, key: string): Promise<void> => {
+export const connect = async (url: string, key: string) => {
const wellKnownUrl = new URL('.well-known/immich', url);
try {
const wellKnown = await fetch(wellKnownUrl).then((response) => response.json());
@@ -50,6 +54,8 @@ export const connect = async (url: string, key: string): Promise<void> => {
logError(error, 'Failed to connect to server');
process.exit(1);
}
+
+ return { url, key };
};
export const logError = (error: unknown, message: string) => {
diff --git a/e2e/src/cli/specs/server-info.e2e-spec.ts b/e2e/src/cli/specs/server-info.e2e-spec.ts
index f207f1fa2e..13eefd3df4 100644
--- a/e2e/src/cli/specs/server-info.e2e-spec.ts
+++ b/e2e/src/cli/specs/server-info.e2e-spec.ts
@@ -11,13 +11,16 @@ describe(`immich server-info`, () => {
it('should return the server info', async () => {
const { stderr, stdout, exitCode } = await immichCli(['server-info']);
expect(stdout.split('\n')).toEqual([
- expect.stringContaining('Server Version:'),
- expect.stringContaining('Image Types:'),
- expect.stringContaining('Video Types:'),
- 'Statistics:',
- ' Images: 0',
- ' Videos: 0',
- ' Total: 0',
+ expect.stringContaining('Server Info (via [email protected]'),
+ ' Url: http://127.0.0.1:2283/api',
+ expect.stringContaining('Version:'),
+ ' Formats:',
+ expect.stringContaining('Images:'),
+ expect.stringContaining('Videos:'),
+ ' Statistics:',
+ ' Images: 0',
+ ' Videos: 0',
+ ' Total: 0',
]);
expect(stderr).toBe('');
expect(exitCode).toBe(0);