Add support for multiple games

Just supporting skyrim and skyrimspecialedition for now.

Move live download count fetching to a context provider. Also adds new games fetching context provider.
This commit is contained in:
2022-09-03 02:51:57 -04:00
parent d103451a40
commit 5ff11d568e
14 changed files with 418 additions and 200 deletions

View File

@@ -1,8 +1,12 @@
export async function jsonFetcher<T>(url: string): Promise<T | null> {
interface Options {
notFoundOk: boolean;
}
export async function jsonFetcher<T>(url: string, options: Options = { notFoundOk: true}): Promise<T | null> {
const res = await fetch(url);
if (!res.ok) {
if (res.status === 404) {
if (res.status === 404 && options.notFoundOk) {
return null;
}
const error = new Error("An error occurred while fetching the data.");
@@ -12,11 +16,11 @@ export async function jsonFetcher<T>(url: string): Promise<T | null> {
return res.json();
};
export async function jsonFetcherWithLastModified<T>(url: string): Promise<{ data: T, lastModified: string | null } | null> {
export async function jsonFetcherWithLastModified<T>(url: string, options: Options = { notFoundOk: true}): Promise<{ data: T, lastModified: string | null } | null> {
const res = await fetch(url);
if (!res.ok) {
if (res.status === 404) {
if (res.status === 404 && options.notFoundOk) {
return null;
}
const error = new Error("An error occurred while fetching the data.");