nice update
This commit is contained in:
+64
-4
@@ -1,11 +1,13 @@
|
||||
async function request(path, options = {}) {
|
||||
const headers = { ...(options.headers || {}) };
|
||||
if (!(options.body instanceof FormData)) {
|
||||
headers['Content-Type'] = headers['Content-Type'] || 'application/json';
|
||||
}
|
||||
|
||||
const res = await fetch(path, {
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(options.headers || {}),
|
||||
},
|
||||
...options,
|
||||
headers,
|
||||
});
|
||||
|
||||
const data = await res.json().catch(() => ({}));
|
||||
@@ -32,7 +34,56 @@ export const api = {
|
||||
case: (id) => request(`/api/cases/${id}`),
|
||||
openCase: (id) => request(`/api/cases/${id}/open`, { method: 'POST' }),
|
||||
inventory: () => request('/api/inventory'),
|
||||
sellInventory: (inventoryItemIds) =>
|
||||
request('/api/inventory/sell', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ inventoryItemIds }),
|
||||
}),
|
||||
shop: () => request('/api/shop'),
|
||||
shopBuy: (packageId) =>
|
||||
request('/api/shop/buy', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ packageId }),
|
||||
}),
|
||||
shopAd: () => request('/api/shop/ad', { method: 'POST' }),
|
||||
feed: () => request('/api/feed'),
|
||||
leaderboard: () => request('/api/leaderboard'),
|
||||
jackpot: () => request('/api/jackpot'),
|
||||
jackpotBet: (inventoryItemIds) =>
|
||||
request('/api/jackpot/bet', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ inventoryItemIds }),
|
||||
}),
|
||||
jackpotWithdraw: (inventoryItemIds) =>
|
||||
request('/api/jackpot/withdraw', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ inventoryItemIds }),
|
||||
}),
|
||||
duels: () => request('/api/duels'),
|
||||
duel: (id) => request(`/api/duels/${id}`),
|
||||
createDuel: (body) =>
|
||||
request('/api/duels', { method: 'POST', body: JSON.stringify(body) }),
|
||||
duelBet: (id, inventoryItemIds) =>
|
||||
request(`/api/duels/${id}/bet`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ inventoryItemIds }),
|
||||
}),
|
||||
duelLeave: (id) => request(`/api/duels/${id}/leave`, { method: 'POST' }),
|
||||
duelCancel: (id) => request(`/api/duels/${id}/cancel`, { method: 'POST' }),
|
||||
duelStart: (id) => request(`/api/duels/${id}/start`, { method: 'POST' }),
|
||||
profile: () => request('/api/profile'),
|
||||
updateProfile: (body) =>
|
||||
request('/api/profile', { method: 'PATCH', body: JSON.stringify(body) }),
|
||||
changePassword: (currentPassword, newPassword) =>
|
||||
request('/api/profile/password', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ currentPassword, newPassword }),
|
||||
}),
|
||||
uploadAvatar: (file) => {
|
||||
const form = new FormData();
|
||||
form.append('avatar', file);
|
||||
return request('/api/profile/avatar', { method: 'POST', body: form });
|
||||
},
|
||||
adminLogin: (username, password) =>
|
||||
request('/api/admin/login', {
|
||||
method: 'POST',
|
||||
@@ -63,8 +114,17 @@ export const api = {
|
||||
}),
|
||||
deleteCaseItem: (id) =>
|
||||
request(`/api/admin/case-items/${id}`, { method: 'DELETE' }),
|
||||
adminUpload: (file) => {
|
||||
const form = new FormData();
|
||||
form.append('image', file);
|
||||
return request('/api/admin/upload', { method: 'POST', body: form });
|
||||
},
|
||||
};
|
||||
|
||||
export function formatCredits(cents) {
|
||||
return (Number(cents) / 100).toFixed(2);
|
||||
}
|
||||
|
||||
export function formatChance(pct) {
|
||||
return `${Number(pct || 0).toFixed(1)}%`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user