first commit
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
async function request(path, options = {}) {
|
||||
const res = await fetch(path, {
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(options.headers || {}),
|
||||
},
|
||||
...options,
|
||||
});
|
||||
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
throw new Error(data.error || `Request failed (${res.status})`);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
export const api = {
|
||||
me: () => request('/api/auth/me'),
|
||||
login: (username, password) =>
|
||||
request('/api/auth/login', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ username, password }),
|
||||
}),
|
||||
register: (username, password) =>
|
||||
request('/api/auth/register', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ username, password }),
|
||||
}),
|
||||
logout: () => request('/api/auth/logout', { method: 'POST' }),
|
||||
cases: () => request('/api/cases'),
|
||||
case: (id) => request(`/api/cases/${id}`),
|
||||
openCase: (id) => request(`/api/cases/${id}/open`, { method: 'POST' }),
|
||||
inventory: () => request('/api/inventory'),
|
||||
leaderboard: () => request('/api/leaderboard'),
|
||||
adminLogin: (username, password) =>
|
||||
request('/api/admin/login', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ username, password }),
|
||||
}),
|
||||
adminCases: () => request('/api/admin/cases'),
|
||||
adminItems: () => request('/api/admin/items'),
|
||||
adminRarities: () => request('/api/admin/rarities'),
|
||||
createCase: (body) =>
|
||||
request('/api/admin/cases', { method: 'POST', body: JSON.stringify(body) }),
|
||||
updateCase: (id, body) =>
|
||||
request(`/api/admin/cases/${id}`, { method: 'PUT', body: JSON.stringify(body) }),
|
||||
deleteCase: (id) => request(`/api/admin/cases/${id}`, { method: 'DELETE' }),
|
||||
createItem: (body) =>
|
||||
request('/api/admin/items', { method: 'POST', body: JSON.stringify(body) }),
|
||||
updateItem: (id, body) =>
|
||||
request(`/api/admin/items/${id}`, { method: 'PUT', body: JSON.stringify(body) }),
|
||||
deleteItem: (id) => request(`/api/admin/items/${id}`, { method: 'DELETE' }),
|
||||
addCaseItem: (caseId, body) =>
|
||||
request(`/api/admin/cases/${caseId}/items`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(body),
|
||||
}),
|
||||
updateCaseItem: (id, body) =>
|
||||
request(`/api/admin/case-items/${id}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(body),
|
||||
}),
|
||||
deleteCaseItem: (id) =>
|
||||
request(`/api/admin/case-items/${id}`, { method: 'DELETE' }),
|
||||
};
|
||||
|
||||
export function formatCredits(cents) {
|
||||
return (Number(cents) / 100).toFixed(2);
|
||||
}
|
||||
Reference in New Issue
Block a user