Reddit Module
Scrapes top Reddit posts from configured subreddits using browser automation.
RedditService
fetchTopPosts(limit: number): Promise<Result<RedditPost[], RedditError>>
Scrapes configured subreddits for top posts:
- Opens browser page via BrowserService
- Iterates subreddits in configured order
- Applies filters: minimum score, max age, max text length, already-processed check
- Returns up to
limitqualifying posts
markAsProcessed(postId, subreddit, title, score): Promise<Result<void, RedditError>>
Records a post as processed to prevent re-scraping.
Time Filter Escalation
When REDDIT_TIME_FILTER_ESCALATION=true (default), if not enough posts are found at the current time filter, the service automatically escalates:
day (48h) → week (168h) → month (720h)
RedditPost
typescript
interface RedditPost {
id: string;
subreddit: string;
title: string;
body: string;
score: number;
url: string;
createdUtc: number;
}Error Codes
| Code | Description |
|---|---|
BROWSER_NOT_READY | Camoufox not initialized |
NAVIGATION_FAILED | Failed to load subreddit page |
SCRAPING_FAILED | DOM parsing error |
NO_POSTS_FOUND | No posts match filters |
PERSISTENCE_FAILED | Database write error |