Enable automatic browsing upvotes
This commit is contained in:
1 parent
27012399ec
commit
7bf1aa9d24
26 files changed
+339
-57
No files matched your search
@@ -89,6 +89,28 @@ export function createGrowthRouter(ctx: WebContext): Router {
|
||||
return res.json({ success: true, account: detail(repo, browsingRepo, accountId, username) });
|
||||
});
|
||||
|
||||
router.post('/growth/:accountId/browsing/run', async (req, res) => {
|
||||
const repo = growth();
|
||||
const browsingRepo = browsing();
|
||||
if (!repo || !browsingRepo) return res.status(503).json({ error: 'Growth storage is unavailable' });
|
||||
const { accountId } = req.params;
|
||||
const username = accountName(accountId);
|
||||
if (username === null) return res.status(404).json({ error: 'Reddit account not found' });
|
||||
|
||||
const runtime = ctx.services.accountRuntimes?.get(accountId);
|
||||
const browsingService = runtime?.resources.browsingService;
|
||||
if (runtime?.snapshot().state !== 'running' || !browsingService) {
|
||||
return res.status(409).json({ error: 'Start this account before running a browsing simulation' });
|
||||
}
|
||||
try {
|
||||
await browsingService.runNow();
|
||||
} catch (error) {
|
||||
return res.status(502).json({ error: `Browsing simulation failed: ${errorMessage(error)}` });
|
||||
}
|
||||
ctx.broadcaster.push('info', `Browsing simulation run manually for u/${username}; no Reddit vote was submitted`);
|
||||
return res.json({ success: true, account: detail(repo, browsingRepo, accountId, username) });
|
||||
});
|
||||
|
||||
router.patch('/growth/:accountId', (req, res) => {
|
||||
const repo = growth();
|
||||
const browsingRepo = browsing();
|
||||
@@ -294,12 +316,13 @@ function presentBrowsing(
|
||||
minimumGapMs: settings.minimumGapMs,
|
||||
jitterMs: settings.jitterMs,
|
||||
allowNsfw: settings.allowNsfw,
|
||||
autoVoteEnabled: settings.autoVoteEnabled,
|
||||
nextDueAt: settings.nextDueAt,
|
||||
updatedAt: settings.updatedAt,
|
||||
},
|
||||
todayTarget: dailyTarget(accountId, day.getTime(), settings),
|
||||
stats: repo.getCountsSince(accountId, day.getTime()),
|
||||
noVotesSubmitted: true as const,
|
||||
noVotesSubmitted: !settings.autoVoteEnabled,
|
||||
...(includeRecent ? {
|
||||
recentDecisions: repo.listRecentSelections(accountId, 50).map((decision) => ({
|
||||
thingFullname: decision.thingFullname,
|
||||
@@ -310,6 +333,7 @@ function presentBrowsing(
|
||||
permalink: decision.permalink,
|
||||
decision: decision.decision,
|
||||
reason: decision.reason,
|
||||
voteSubmitted: decision.voteSubmitted,
|
||||
decidedAt: decision.decidedAt,
|
||||
})),
|
||||
} : {}),
|
||||
|
||||
Reference in new issue
Block a user