+21
-33
@@ -1,47 +1,35 @@
|
||||
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 credential availability')
|
||||
.description('Check twitter safe relay availability')
|
||||
.action(async () => {
|
||||
const opts = program.opts();
|
||||
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
||||
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
||||
const relayBaseUrl = ctx.resolveRelayBaseUrlFromOptions(opts);
|
||||
|
||||
console.log(`${ctx.p('info')}Credential check`);
|
||||
console.log('─'.repeat(40));
|
||||
console.log(`${ctx.p('info')}Relay check`);
|
||||
console.log('-'.repeat(40));
|
||||
|
||||
if (cookies.authToken) {
|
||||
console.log(`${ctx.p('ok')}auth_token: ${cookies.authToken.slice(0, 10)}...`);
|
||||
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, 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')}auth_token: not found`);
|
||||
}
|
||||
|
||||
if (cookies.ct0) {
|
||||
console.log(`${ctx.p('ok')}ct0: ${cookies.ct0.slice(0, 10)}...`);
|
||||
} else {
|
||||
console.log(`${ctx.p('err')}ct0: not found`);
|
||||
}
|
||||
|
||||
if (cookies.source) {
|
||||
console.log(`${ctx.l('source')}${cookies.source}`);
|
||||
}
|
||||
|
||||
if (warnings.length > 0) {
|
||||
console.log(`\n${ctx.p('warn')}Warnings:`);
|
||||
for (const warning of warnings) {
|
||||
console.log(` - ${warning}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (cookies.authToken && cookies.ct0) {
|
||||
console.log(`\n${ctx.p('ok')}Ready to tweet!`);
|
||||
} else {
|
||||
console.log(`\n${ctx.p('err')}Missing credentials. Options:`);
|
||||
console.log(' 1. Login to x.com in Safari/Chrome/Firefox');
|
||||
console.log(' 2. Set AUTH_TOKEN and CT0 environment variables');
|
||||
console.log(' 3. Use --auth-token and --ct0 flags');
|
||||
console.log(`${ctx.p('err')}Relay check failed: ${result.error ?? 'Unknown error'}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user