Public Access
feat(library): search IGDB and add games by hand
This commit is contained in:
1 parent
d9a39dda22
commit
444b03acee
17 files changed
+699
-35
No files matched your search
@@ -0,0 +1,33 @@
|
||||
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;
|
||||
|
||||
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'});
|
||||
Reference in new issue
Block a user