Fetch info about reddit sub

This commit is contained in:
Alicia Sykes 2024-03-24 13:00:27 +00:00
parent f6aeaf0573
commit 3806d4755b
1 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,38 @@
export const fetchRedditInfo = async (subreddit: string): Promise<RedditData | null> => {
const endpoint = `https://subreddit-info.as93.net/${subreddit}`;
try {
return await fetch(endpoint).then((res) => res.json());
} catch (error) {
console.error('Error fetching reddit data:', error);
return null;
}
};
interface SubredditInfo {
name: string | null;
title: string | null;
description: string | null;
longDescription: string | null;
icon: string | null;
banner: string | null;
color: string | null;
subscribers: number | null;
activeSubscribers: number | null;
dateCreated: number | null;
descriptionHtml: string | null;
}
interface Post {
title: string;
body: string;
upVotes: number;
downVotes: number;
date: number;
url: string;
}
export interface RedditData {
info: SubredditInfo;
posts: Post[];
}