Reviews: a store read that failed everywhere is an error, not an empty fresh list; Reviews tab says Apple's API can lag and Play returns 7 days; pitfall 106

This commit is contained in:
CRTkafa 2026-10-23 00:33:27 +08:00
parent 0e88e4293a
commit 75bf62e125
7 changed files with 50 additions and 8 deletions

View file

@ -21,7 +21,7 @@ import { confirm } from './lib/ctx';
import { done, log, printJson, warn } from './lib/log';
import {
checkReply, type Draft, draftMarkdown, draftName, filterReviews, markSent, parseAppleReviews, parseDraft, parsePlayReviews, replyRequest,
type Review, sendPlan,
type Review, sendPlan, settleStoreReads, type StoreRead,
} from './lib/reviews';
import { textTable } from './lib/table';
import { readReplyDrafts, setApproved, setReplyText } from './lib/project-files';
@ -63,13 +63,13 @@ async function collect(ctx: Ctx, o: { since: string; unanswered: boolean; rating
const { config } = ctx.loaded;
const store = ctx.args.get('store');
if (store && store !== 'apple' && store !== 'play') throw new Error('--store apple | play');
const all: Review[] = [];
if ((!store || store === 'apple') && config.apple) {
try { all.push(...await appleReviews(ctx, o.since)); } catch (e) { if (store) throw e; warn(TAG, `apple: ${(e as Error).message.slice(0, 200)}`); }
}
if ((!store || store === 'play') && config.play) {
try { all.push(...await playReviews(ctx)); } catch (e) { if (store) throw e; warn(TAG, `play: ${(e as Error).message.slice(0, 200)}`); }
const reads: StoreRead[] = [];
for (const [name, on, read] of [['apple', !!config.apple, () => appleReviews(ctx, o.since)], ['play', !!config.play, () => playReviews(ctx)]] as const) {
if (store && store !== name || !on) continue;
try { reads.push({ store: name, reviews: await read() }); } catch (e) { if (store) throw e; reads.push({ store: name, error: (e as Error).message.slice(0, 200) }); }
}
const { reviews: all, errors } = settleStoreReads(reads);
for (const e of errors) warn(TAG, e);
return filterReviews(all, o);
}