+ category::fetch_category_videos for easy json fetches

This commit is contained in:
shockrah 2022-03-26 22:13:55 -07:00
parent 2411e39e87
commit 40e2d9d4be

View File

@ -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<Array<VideoMeta>> {
const endpoint = window.location.origin + '/api' + window.location.pathname
let videos: Array<VideoMeta> = []
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
}