feat: add logout to cli

This commit is contained in:
Jonathan Jogenfors 2023-11-10 20:59:16 +01:00
parent f588416659
commit 015d8d8267
6 changed files with 16 additions and 8 deletions

View file

@ -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
```

View file

@ -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<void> {

View file

@ -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';

View file

@ -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();

View file

@ -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);

View file

@ -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<void> {
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') {