This commit is contained in:
parent
4aac791c75
commit
81437ede41
5 changed files with 22 additions and 17 deletions
|
@ -2,11 +2,11 @@ import fetch from "got-cjs";
|
|||
import * as htmlparser from "htmlparser2";
|
||||
|
||||
export default class ImageHelper {
|
||||
public static async FetchImageFromRedditGallery(url: string): Promise<string[] | undefined> {
|
||||
public static async FetchImageFromRedditGallery(url: string): Promise<string[]> {
|
||||
const fetched = await fetch(url);
|
||||
|
||||
if (!fetched || fetched.errored || fetched.statusCode != 200) {
|
||||
return undefined;
|
||||
return [];
|
||||
}
|
||||
|
||||
const dom = htmlparser.parseDocument(fetched.body);
|
||||
|
|
|
@ -93,7 +93,7 @@ export default async function randomBunny(subreddit: string, sortBy: "new" | "ho
|
|||
const randomData = randomSelect.data;
|
||||
|
||||
let url: string;
|
||||
let gallery: string[] = [];
|
||||
let gallery: string[];
|
||||
|
||||
if (randomData.url.includes("/gallery")) {
|
||||
const galleryImage = await ImageHelper.FetchImageFromRedditGallery(randomData.url);
|
||||
|
@ -117,6 +117,7 @@ export default async function randomBunny(subreddit: string, sortBy: "new" | "ho
|
|||
gallery = galleryImage;
|
||||
} else {
|
||||
url = randomData.url;
|
||||
gallery = [randomData.url];
|
||||
}
|
||||
|
||||
const redditResult: IRedditResult = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue