diff --git a/cli/README.md b/cli/README.md index 2add73310..213ab7b5e 100644 --- a/cli/README.md +++ b/cli/README.md @@ -1,10 +1,10 @@ -A command-line interface for interfacing with Immich +A command-line interface for interfacing with the self-hosted photo manager [Immich](https://immich.app/). # Installing To use the cli, run - $ npm install @immich/cli´ + $ npm install @immich/cli # Usage @@ -34,9 +34,9 @@ Options: Commands: upload [options] [paths...] Upload assets - import [options] [paths...] Import existing assets server-info Display server information login-key [instanceUrl] [apiKey] Login using an API key + logout Remove stored credentials help [command] display help for command ``` diff --git a/cli/src/commands/login/key.ts b/cli/src/commands/login/key.ts index 81d2fcb4f..b348caa35 100644 --- a/cli/src/commands/login/key.ts +++ b/cli/src/commands/login/key.ts @@ -1,4 +1,4 @@ -import { BaseCommand } from 'src/cli/base-command'; +import { BaseCommand } from '../../cli/base-command'; export default class LoginKey extends BaseCommand { public async run(instanceUrl: string, apiKey: string): Promise { diff --git a/cli/src/commands/logout.ts b/cli/src/commands/logout.ts index d27e2c0f2..86f5151e0 100644 --- a/cli/src/commands/logout.ts +++ b/cli/src/commands/logout.ts @@ -1,4 +1,4 @@ -import { BaseCommand } from 'src/cli/base-command'; +import { BaseCommand } from '../cli/base-command'; export default class Logout extends BaseCommand { public static readonly description = 'Logout and remove persisted credentials'; diff --git a/cli/src/commands/upload.ts b/cli/src/commands/upload.ts index 748169f37..701f3b340 100644 --- a/cli/src/commands/upload.ts +++ b/cli/src/commands/upload.ts @@ -1,4 +1,3 @@ -import { BaseCommand } from 'src/cli/base-command'; import { CrawledAsset } from '../cores/models/crawled-asset'; import { CrawlService, UploadService } from '../services'; import * as si from 'systeminformation'; @@ -8,6 +7,7 @@ import { CrawlOptionsDto } from '../cores/dto/crawl-options-dto'; import cliProgress from 'cli-progress'; import byteSize from 'byte-size'; +import { BaseCommand } from '../cli/base-command'; export default class Upload extends BaseCommand { private crawlService = new CrawlService(); diff --git a/cli/src/index.ts b/cli/src/index.ts index 3203bb123..f808f9595 100644 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -4,6 +4,7 @@ import { program, Option } from 'commander'; import Upload from './commands/upload'; import ServerInfo from './commands/server-info'; import LoginKey from './commands/login/key'; +import Logout from './commands/logout'; program.name('immich').description('Immich command line interface'); @@ -43,4 +44,11 @@ program await new LoginKey().run(paths, options); }); +program + .command('logout') + .description('Remove stored credentials') + .action(async (paths, options) => { + await new Logout().run(); + }); + program.parse(process.argv); diff --git a/cli/src/services/session.service.ts b/cli/src/services/session.service.ts index fb008b128..d1c9d789c 100644 --- a/cli/src/services/session.service.ts +++ b/cli/src/services/session.service.ts @@ -46,7 +46,7 @@ export class SessionService { // Check if server and api key are valid const { data: userInfo } = await this.api.userApi.getMyUserInfo().catch((error) => { - throw new LoginError(`Failed to connect to the server: ${error.message}`); + throw new LoginError(`Failed to connect to server ${instanceUrl}: ${error.message}`); }); console.log(`Logged in as ${userInfo.email}`); @@ -78,7 +78,7 @@ export class SessionService { private async ping(): Promise { const { data: pingResponse } = await this.api.serverInfoApi.pingServer().catch((error) => { - throw new Error(`Failed to connect to the server: ${error.message}`); + throw new Error(`Failed to connect to server ${this.api.apiConfiguration.instanceUrl}: ${error.message}`); }); if (pingResponse.res !== 'pong') {