mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
feat(cli): better server info output (#8307)
* feat(cli): server-info command prints url and user email * chore: clean up --------- Co-authored-by: 澪 <mio@mio19.uk>
This commit is contained in:
parent
916603d2d4
commit
613b544bf0
3 changed files with 39 additions and 21 deletions
|
|
@ -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) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue