2023-11-20 00:16:24 +02:00
|
|
|
#! /usr/bin/env node
|
2024-01-30 14:55:34 +02:00
|
|
|
import { Command, Option } from 'commander';
|
2023-12-19 04:29:26 +02:00
|
|
|
import path from 'node:path';
|
2024-02-02 05:18:00 +02:00
|
|
|
import os from 'node:os';
|
2024-01-30 14:55:34 +02:00
|
|
|
import { version } from '../package.json';
|
2024-02-06 13:17:15 +02:00
|
|
|
import { LoginCommand } from './commands/login.command';
|
2024-01-30 14:55:34 +02:00
|
|
|
import { LogoutCommand } from './commands/logout.command';
|
|
|
|
import { ServerInfoCommand } from './commands/server-info.command';
|
|
|
|
import { UploadCommand } from './commands/upload.command';
|
2023-12-19 04:29:26 +02:00
|
|
|
|
2024-02-06 13:17:15 +02:00
|
|
|
const defaultConfigDirectory = path.join(os.homedir(), '.config/immich/');
|
2023-12-19 04:29:26 +02:00
|
|
|
|
|
|
|
const program = new Command()
|
|
|
|
.name('immich')
|
|
|
|
.version(version)
|
|
|
|
.description('Command line interface for Immich')
|
2024-02-06 13:17:15 +02:00
|
|
|
.addOption(
|
|
|
|
new Option('-d, --config-directory', 'Configuration directory where auth.yml will be stored')
|
|
|
|
.env('IMMICH_CONFIG_DIR')
|
|
|
|
.default(defaultConfigDirectory),
|
|
|
|
);
|
2023-07-06 16:37:47 +02:00
|
|
|
|
|
|
|
program
|
|
|
|
.command('upload')
|
|
|
|
.description('Upload assets')
|
|
|
|
.usage('[options] [paths...]')
|
|
|
|
.addOption(new Option('-r, --recursive', 'Recursive').env('IMMICH_RECURSIVE').default(false))
|
|
|
|
.addOption(new Option('-i, --ignore [paths...]', 'Paths to ignore').env('IMMICH_IGNORE_PATHS'))
|
|
|
|
.addOption(new Option('-h, --skip-hash', "Don't hash files before upload").env('IMMICH_SKIP_HASH').default(false))
|
2024-02-06 12:00:35 +02:00
|
|
|
.addOption(new Option('-H, --include-hidden', 'Include hidden folders').env('IMMICH_INCLUDE_HIDDEN').default(false))
|
2023-07-06 16:37:47 +02:00
|
|
|
.addOption(
|
2023-11-20 00:16:24 +02:00
|
|
|
new Option('-a, --album', 'Automatically create albums based on folder name')
|
|
|
|
.env('IMMICH_AUTO_CREATE_ALBUM')
|
2023-07-06 16:37:47 +02:00
|
|
|
.default(false),
|
|
|
|
)
|
2023-12-20 17:51:53 +02:00
|
|
|
.addOption(
|
|
|
|
new Option('-A, --album-name <name>', 'Add all assets to specified album')
|
|
|
|
.env('IMMICH_ALBUM_NAME')
|
|
|
|
.conflicts('album'),
|
|
|
|
)
|
2023-07-06 16:37:47 +02:00
|
|
|
.addOption(
|
|
|
|
new Option('-n, --dry-run', "Don't perform any actions, just show what will be done")
|
|
|
|
.env('IMMICH_DRY_RUN')
|
|
|
|
.default(false),
|
|
|
|
)
|
2023-11-20 00:16:24 +02:00
|
|
|
.addOption(new Option('--delete', 'Delete local assets after upload').env('IMMICH_DELETE_ASSETS'))
|
|
|
|
.argument('[paths...]', 'One or more paths to assets to be uploaded')
|
2023-10-13 07:22:40 +02:00
|
|
|
.action(async (paths, options) => {
|
2023-11-20 00:16:24 +02:00
|
|
|
options.exclusionPatterns = options.ignore;
|
2024-01-30 14:55:34 +02:00
|
|
|
await new UploadCommand(program.opts()).run(paths, options);
|
2023-07-06 16:37:47 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
program
|
|
|
|
.command('server-info')
|
|
|
|
.description('Display server information')
|
2023-10-13 07:22:40 +02:00
|
|
|
.action(async () => {
|
2024-01-30 14:55:34 +02:00
|
|
|
await new ServerInfoCommand(program.opts()).run();
|
2023-07-06 16:37:47 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
program
|
|
|
|
.command('login-key')
|
|
|
|
.description('Login using an API key')
|
|
|
|
.argument('[instanceUrl]')
|
|
|
|
.argument('[apiKey]')
|
2023-10-13 07:22:40 +02:00
|
|
|
.action(async (paths, options) => {
|
2024-01-30 14:55:34 +02:00
|
|
|
await new LoginCommand(program.opts()).run(paths, options);
|
2023-07-06 16:37:47 +02:00
|
|
|
});
|
|
|
|
|
2023-11-20 00:16:24 +02:00
|
|
|
program
|
|
|
|
.command('logout')
|
|
|
|
.description('Remove stored credentials')
|
|
|
|
.action(async () => {
|
2024-01-30 14:55:34 +02:00
|
|
|
await new LogoutCommand(program.opts()).run();
|
2023-11-20 00:16:24 +02:00
|
|
|
});
|
|
|
|
|
2023-07-06 16:37:47 +02:00
|
|
|
program.parse(process.argv);
|