Commit 3806d4755b
Unsigned
Layout: unified · split
web/src/utils/fetch-reddit-info.ts added +38
| @@ -0,0 +1,38 @@ | ||
| 1 | ||
| 2 | export const fetchRedditInfo = async (subreddit: string): Promise<RedditData | null> => { | |
| 3 | const endpoint = `https://subreddit-info.as93.net/${subreddit}`; | |
| 4 | try { | |
| 5 | return await fetch(endpoint).then((res) => res.json()); | |
| 6 | } catch (error) { | |
| 7 | console.error('Error fetching reddit data:', error); | |
| 8 | return null; | |
| 9 | } | |
| 10 | }; | |
| 11 | ||
| 12 | interface SubredditInfo { | |
| 13 | name: string | null; | |
| 14 | title: string | null; | |
| 15 | description: string | null; | |
| 16 | longDescription: string | null; | |
| 17 | icon: string | null; | |
| 18 | banner: string | null; | |
| 19 | color: string | null; | |
| 20 | subscribers: number | null; | |
| 21 | activeSubscribers: number | null; | |
| 22 | dateCreated: number | null; | |
| 23 | descriptionHtml: string | null; | |
| 24 | } | |
| 25 | ||
| 26 | interface Post { | |
| 27 | title: string; | |
| 28 | body: string; | |
| 29 | upVotes: number; | |
| 30 | downVotes: number; | |
| 31 | date: number; | |
| 32 | url: string; | |
| 33 | } | |
| 34 | ||
| 35 | export interface RedditData { | |
| 36 | info: SubredditInfo; | |
| 37 | posts: Post[]; | |
| 38 | } | |