From 40e2d9d4befafecac5b1c5d4abd3b4bff7c53c7b Mon Sep 17 00:00:00 2001 From: shockrah Date: Sat, 26 Mar 2022 22:13:55 -0700 Subject: [PATCH] + category::fetch_category_videos for easy json fetches --- ts/category.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ts/category.ts b/ts/category.ts index 0061cd5..48b7562 100644 --- a/ts/category.ts +++ b/ts/category.ts @@ -1,4 +1,4 @@ -export class VideoMeta { +class VideoMeta { name: string|null thumbnail: string|null category: string @@ -79,4 +79,16 @@ export class VideoMeta { } } +export async function fetch_category_videos() : Promise> { + const endpoint = window.location.origin + '/api' + window.location.pathname + let videos: Array = [] + const response = await fetch(endpoint) + if(response.headers.get('Content-Type') == 'application/json') { + const raw = JSON.parse(await response.text()) + for(const vid_raw of raw) { + videos.push(new VideoMeta(vid_raw)) + } + } + return videos +}