Working on upload images and tilemap

This commit is contained in:
Benjamin Sherriff
2023-10-23 16:17:07 -04:00
parent 8b4d4e1b1f
commit 3eb888b57d
22 changed files with 987 additions and 656 deletions

View File

@@ -8,7 +8,7 @@ export async function get(endpoint: string, params: Record<string, any> = {}): P
// Remove undefined params
Object.keys(params).forEach((key) => params[key] === undefined && delete params[key]);
const urlParams = new URLSearchParams(params);
const url = urlParams ? `${baseURL}/${endpoint}?${urlParams}` : `${baseURL}/${endpoint}`;
const url = urlParams && urlParams.size > 0 ? `${baseURL}/${endpoint}?${urlParams}` : `${baseURL}/${endpoint}`;
const response = await fetch(url, {
method: 'GET',
credentials: 'include'
@@ -16,11 +16,15 @@ export async function get(endpoint: string, params: Record<string, any> = {}): P
return response;
}
export async function post(endpoint: string, body = {}): Promise<Response> {
interface PostOptions {
headers?: Record<string, any>;
}
export async function post(endpoint: string, body = {}, options?: PostOptions): Promise<Response> {
const url = `${baseURL}/${endpoint}`;
const response = await fetch(url, {
method: 'POST',
headers: {
headers: options?.headers || {
'Content-Type': 'application/json'
},
credentials: 'include',