38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import type { Command } from 'commander';
|
|
import type { CliContext } from '../cli/shared.js';
|
|
import { TwitterClient } from '../lib/twitter-client.js';
|
|
|
|
export function registerCheckCommand(program: Command, ctx: CliContext): void {
|
|
program
|
|
.command('check')
|
|
.description('Check twitter safe relay availability')
|
|
.action(async () => {
|
|
const opts = program.opts();
|
|
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
const relayBaseUrl = ctx.resolveRelayBaseUrlFromOptions(opts);
|
|
const profileName = ctx.resolveProfileNameFromOptions(opts);
|
|
|
|
console.log(`${ctx.p('info')}Relay check`);
|
|
console.log('-'.repeat(40));
|
|
|
|
if (!relayBaseUrl) {
|
|
console.log(`${ctx.p('err')}TWITTER_RELAY_BASE_URL: not set`);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log(`${ctx.p('ok')}relay: ${relayBaseUrl}`);
|
|
|
|
const client = new TwitterClient({ relayBaseUrl, profileName, timeoutMs });
|
|
const result = await client.getCurrentUser();
|
|
|
|
if (result.success && result.user) {
|
|
console.log(`${ctx.l('user')}@${result.user.username} (${result.user.name})`);
|
|
console.log(`${ctx.l('userId')}${result.user.id}`);
|
|
console.log(`\n${ctx.p('ok')}Ready to use twitter safe relay.`);
|
|
} else {
|
|
console.log(`${ctx.p('err')}Relay check failed: ${result.error ?? 'Unknown error'}`);
|
|
process.exit(1);
|
|
}
|
|
});
|
|
}
|