mirror of
https://gitlab1.ptb.de/waltem01/Matrix
synced 2024-11-14 00:43:50 +00:00
endpoint for reddit 'redirect'
This commit is contained in:
parent
a92193f33b
commit
4d6867e690
22
Webserver/src/routes/api/reddit/+server.ts
Normal file
22
Webserver/src/routes/api/reddit/+server.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import type { APIResponse } from "$lib/interfaces";
|
||||||
|
import { json, type RequestHandler } from "@sveltejs/kit";
|
||||||
|
|
||||||
|
export const GET: RequestHandler = async ({ url }) => {
|
||||||
|
// Get endpoint on main API from searchparams
|
||||||
|
const params = url.searchParams;
|
||||||
|
const subreddit = params.get('subreddit');
|
||||||
|
// Return if param not found
|
||||||
|
if (subreddit === null) return json({ success: false } as APIResponse);
|
||||||
|
|
||||||
|
// Get subreddit page data
|
||||||
|
const response = await fetch(`https://www.reddit.com/r/${subreddit}/`, {
|
||||||
|
headers: new Headers({
|
||||||
|
"User-Agent": "MatrixRedditMemes/0.0.1"
|
||||||
|
})
|
||||||
|
});
|
||||||
|
// Read data as string
|
||||||
|
const text = await response.text();
|
||||||
|
|
||||||
|
// Return source data
|
||||||
|
return json({ success: true, results: text.split('\n') } as APIResponse);
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user