Files
ToBePlayed-Frontend/src/utils/manualGames.js
T
lobo 24a98062ee
Build, Test & Push Frontend / quality-check (push) Successful in 19s
Build, Test & Push Frontend / docker (push) Successful in 27s
refactor(limits): server limits in one file, own texts for unknown errors
2026-09-29 14:48:28 +02:00

37 lines
1.6 KiB
JavaScript

import {apiFetch} from './api.js';
const LIBRARY_URL = () => `${import.meta.env.VITE_CORE_API_URL}/api/library`;
const JSON_HEADERS = {'Content-Type': 'application/json'};
// A game that is not on Steam has a negative key (minus its IGDB id). Steam art and the Steam store exist only for
// positive keys; Auth also takes only those as background or banner.
export const isSteamKey = (appid) => Number(appid) > 0;
// Two decimals: then hoursToMinutes gives back the same minute.
export const toHours = (minutes) => (minutes > 0 ? String(Math.round((minutes / 60) * 100) / 100) : '');
export const hoursToMinutes = (hours) => {
const value = Number(String(hours).replace(',', '.'));
return Number.isFinite(value) && value > 0 ? Math.round(value * 60) : 0;
};
// The calls return the raw response; the caller handles the status.
export const searchGames = (query, signal) =>
apiFetch(`${LIBRARY_URL()}/game-search?${new URLSearchParams({q: query.trim()})}`, {signal});
export const addGame = ({igdbId, platform, status, playtimeMinutes}) =>
apiFetch(`${LIBRARY_URL()}/games`, {
method: 'POST',
headers: JSON_HEADERS,
body: JSON.stringify({igdbId, platform, status, playtimeMinutes}),
});
export const updateManualGame = (appid, {platform, playtimeMinutes}) =>
apiFetch(`${LIBRARY_URL()}/games/${appid}/manual`, {
method: 'PUT',
headers: JSON_HEADERS,
body: JSON.stringify({platform, playtimeMinutes}),
});
export const removeGame = (appid) => apiFetch(`${LIBRARY_URL()}/games/${appid}`, {method: 'DELETE'});