From f2cb9167827d1a41b8575e0ce41d691d96014180 Mon Sep 17 00:00:00 2001 From: waltem01 Date: Thu, 22 Feb 2024 10:41:17 +0100 Subject: [PATCH] filtering all sources of post images --- Webserver/src/routes/api/reddit/+server.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Webserver/src/routes/api/reddit/+server.ts b/Webserver/src/routes/api/reddit/+server.ts index 6e58e77..b3729e7 100644 --- a/Webserver/src/routes/api/reddit/+server.ts +++ b/Webserver/src/routes/api/reddit/+server.ts @@ -17,6 +17,12 @@ export const GET: RequestHandler = async ({ url }) => { // Read data as string const text = await response.text(); + // Get all sources of posts + const regex = /]+role="presentation"[^>]+src="(.*?)"[^>]*>/g; + let results = [], match; + while ((match = regex.exec(text)) !== null) + results.push(match[1]); + // Return source data - return json({ success: true, results: text.split('\n') } as APIResponse); + return json({ success: true, results } as APIResponse); };