1
0
Fork 0
This repository has been archived on 2023-12-03. You can view files and clone it, but cannot push or open issues or pull requests.
chellaris-galaxy-political-.../components/server/fetchers.ts

27 lines
714 B
TypeScript

import { Game } from "@/types/stellaris"
type Parameter = {
key: string,
val: string | number
}
const baseUrl = 'https://www.chellaris.net/api/v2'
export const generateUrl = (url: string, params?: Parameter[]) => {
let query: string = baseUrl + url;
if (params && params.length > 0) {
query = query + '?';
params.forEach((param, idx) => {
query = query + param.key + '=' + param.val;
if (idx + 1 != params.length) {
query = query + '&';
}
});
}
return query;
}
export const fetchGameGroups = async (game: Game) => {
const gameGroups = await fetch(generateUrl('/game_groups', [{key: "game_id", val: game.id}])).then((res) => res.json())
return gameGroups
}