feat(graphql): runtime query-id refresh
This commit is contained in:
@@ -28,6 +28,7 @@ import {
|
||||
resolveOutputConfigFromCommander,
|
||||
statusPrefix,
|
||||
} from './lib/output.js';
|
||||
import { runtimeQueryIds } from './lib/runtime-query-ids.js';
|
||||
import { SweetisticsClient } from './lib/sweetistics-client.js';
|
||||
import { type TweetData, TwitterClient } from './lib/twitter-client.js';
|
||||
import { getCliVersion } from './lib/version.js';
|
||||
@@ -110,6 +111,7 @@ const config = loadConfig();
|
||||
const KNOWN_COMMANDS = new Set([
|
||||
'tweet',
|
||||
'reply',
|
||||
'query-ids',
|
||||
'read',
|
||||
'replies',
|
||||
'thread',
|
||||
@@ -267,6 +269,63 @@ program
|
||||
cmd.outputHelp();
|
||||
});
|
||||
|
||||
program
|
||||
.command('query-ids')
|
||||
.description('Show or refresh cached Twitter GraphQL query IDs')
|
||||
.option('--json', 'Output as JSON')
|
||||
.option('--fresh', 'Force refresh (downloads X client bundles)', false)
|
||||
.action(async (cmdOpts: { json?: boolean; fresh?: boolean }) => {
|
||||
const operations = [
|
||||
'CreateTweet',
|
||||
'CreateRetweet',
|
||||
'FavoriteTweet',
|
||||
'TweetDetail',
|
||||
'SearchTimeline',
|
||||
'UserArticlesTweets',
|
||||
];
|
||||
|
||||
if (cmdOpts.fresh) {
|
||||
console.error(`${p('info')}Refreshing GraphQL query IDs…`);
|
||||
await runtimeQueryIds.refresh(operations, { force: true });
|
||||
}
|
||||
|
||||
const info = await runtimeQueryIds.getSnapshotInfo();
|
||||
if (!info) {
|
||||
if (cmdOpts.json) {
|
||||
console.log(JSON.stringify({ cached: false, cachePath: runtimeQueryIds.cachePath }, null, 2));
|
||||
return;
|
||||
}
|
||||
console.log(`${p('warn')}No cached query IDs yet.`);
|
||||
console.log(`${p('info')}Run: bird query-ids --fresh`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmdOpts.json) {
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
{
|
||||
cached: true,
|
||||
cachePath: info.cachePath,
|
||||
fetchedAt: info.snapshot.fetchedAt,
|
||||
isFresh: info.isFresh,
|
||||
ageMs: info.ageMs,
|
||||
ids: info.snapshot.ids,
|
||||
discovery: info.snapshot.discovery,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`${p('ok')}GraphQL query IDs cached`);
|
||||
console.log(`path: ${info.cachePath}`);
|
||||
console.log(`fetched_at: ${info.snapshot.fetchedAt}`);
|
||||
console.log(`fresh: ${info.isFresh ? 'yes' : 'no'}`);
|
||||
console.log(`ops: ${Object.keys(info.snapshot.ids).length}`);
|
||||
});
|
||||
|
||||
// Tweet command
|
||||
program
|
||||
.command('tweet')
|
||||
|
||||
Reference in New Issue
Block a user