import {apiFetch} from './api.js'; import {ROLES} from './admin.js'; const JSON_HEADERS = {'Content-Type': 'application/json'}; const url = (appid, field) => `${import.meta.env.VITE_CORE_API_URL}/api/library/games/${appid}/corrections/${field}`; /** * IGDB's genre names, the values Core stores. Each has a STATS.GENRE key (see genreKey). */ export const IGDB_GENRES = ['Adventure', 'Arcade', 'Card & Board Game', 'Fighting', "Hack and slash/Beat 'em up", 'Indie', 'MOBA', 'Music', 'Pinball', 'Platform', 'Point-and-click', 'Puzzle', 'Quiz/Trivia', 'Racing', 'Real Time Strategy (RTS)', 'Role-playing (RPG)', 'Shooter', 'Simulator', 'Sport', 'Strategy', 'Tactical', 'Turn-based strategy (TBS)', 'Visual Novel']; // SPEEDRUN is the speedrun link, not a stored mood. export const CORRECTABLE_MOODS = ['STORY', 'COOP', 'CHILL', 'ACTION', 'SCARY']; /** * An AUDITOR or higher, by the active role: an admin viewing as USER cannot correct. */ export const canCorrect = (currentUser) => !!currentUser && ROLES.indexOf(currentUser.activeRole) >= ROLES.indexOf('AUDITOR'); /** * PUT: 204, 400 {code: INVALID_CORRECTION, message}, 403 below AUDITOR, 404 unknown game. */ export const saveCorrection = (appid, field, value) => apiFetch(url(appid, field), {method: 'PUT', headers: JSON_HEADERS, body: JSON.stringify({value})}); /** * DELETE: back to the source's value, 204. */ export const resetCorrection = (appid, field) => apiFetch(url(appid, field), {method: 'DELETE'}); /** * POST: 200 {appid} = the key the game lives under now; 400 {code: SAME_GAME | STEAM_GAMES}, 403 below AUDITOR, * 404 {code: GAME_NOT_FOUND} for a game not in ToBePlayed. */ export const mergeGame = (appid, otherAppid) => apiFetch(`${import.meta.env.VITE_CORE_API_URL}/api/library/games/${appid}/merge`, {method: 'POST', headers: JSON_HEADERS, body: JSON.stringify({otherAppid})});