mirror of
https://github.com/romancm/gamebrary
synced 2024-11-10 05:34:15 +00:00
IGDB v3 endpoints
This commit is contained in:
parent
21be1e0cd5
commit
6fef316deb
1 changed files with 66 additions and 36 deletions
|
@ -4,7 +4,7 @@ const axios = require('axios');
|
|||
axios.defaults.headers.common['user-key'] = functions.config().igdb.key;
|
||||
|
||||
const igdbUrl = 'https://api-endpoint.igdb.com';
|
||||
const igdbV3Url = 'https://api-v3.igdb.com/search/';
|
||||
const igdbV3Url = 'https://api-v3.igdb.com/';
|
||||
const igdbFields = 'id,name,slug,created_at,updated_at,summary,rating,category,player_perspectives,release_dates,name,cover,platforms,screenshots,videos,websites,esrb,pegi,themes.name,game.name&expand=game,themes,developers,publishers,game_engines,game_modes,genres,platforms,player_perspectives';
|
||||
const igdbV3Fields = 'fields alternative_name,character,collection,company,description,game,name,person,platform,popularity,published_at,test_dummy,theme;';
|
||||
const igdbFieldsMinimal = 'id,name,slug,rating,name,cover';
|
||||
|
@ -22,7 +22,7 @@ exports.search = functions.https.onRequest((req, res) => {
|
|||
exports.games = functions.https.onRequest((req, res) => {
|
||||
res.set('Access-Control-Allow-Origin', "*")
|
||||
|
||||
const { games, platformId } = req.query;
|
||||
const { games } = req.query;
|
||||
|
||||
axios.get(`${igdbUrl}/games/${games}/?fields=${igdbFieldsMinimal}`)
|
||||
.then(({ data }) => { res.status(200).send(data) })
|
||||
|
@ -69,43 +69,73 @@ exports.email = functions.https.onRequest((req, res) => {
|
|||
.catch(() => { res.send(400) });
|
||||
});
|
||||
|
||||
exports.platform = functions.https.onRequest((req, res) => {
|
||||
exports.searchV2 = functions.https.onRequest((req, res) => {
|
||||
res.set('Access-Control-Allow-Origin', "*")
|
||||
|
||||
const { platformId } = req.query;
|
||||
const { search, platform } = req.query;
|
||||
|
||||
axios.get(`${igdbUrl}/platforms/${platformId}`)
|
||||
const data = `search "${search}"; fields id,name,slug,rating,name,cover.url; where platforms = (${platform});`
|
||||
|
||||
axios({
|
||||
url: 'https://api-v3.igdb.com/games',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'user-key': '3b516a46c3af209bb6e287e9090d720c'
|
||||
},
|
||||
data,
|
||||
})
|
||||
.then(({ data }) => { res.status(200).send(data) })
|
||||
.catch(() => { res.send(400) });
|
||||
});
|
||||
//
|
||||
// // IGDB V3
|
||||
// exports.searchV3 = functions.https.onRequest((req, res) => {
|
||||
// res.set('Access-Control-Allow-Origin', "*")
|
||||
//
|
||||
// const { searchText, platform } = req.query;
|
||||
//
|
||||
// const data = `
|
||||
// search "${searchText}";
|
||||
// fields game.*;
|
||||
// where game != null;
|
||||
// `;
|
||||
//
|
||||
// console.log(data);
|
||||
//
|
||||
// axios({
|
||||
// url: igdbV3Url,
|
||||
// method: 'POST',
|
||||
// headers: {
|
||||
// 'Accept': 'application/json',
|
||||
// 'user-key': '3b516a46c3af209bb6e287e9090d720c'
|
||||
// },
|
||||
// data,
|
||||
// })
|
||||
// .then(({ data }) => { res.status(200).send(data) })
|
||||
// .catch(() => { res.send(400) });
|
||||
// // res.send(req.body)
|
||||
// // axios.get(`${igdbV3Url}/games/?search=${searchText}&fields=${igdbFields}&filter[platforms][eq]=${platformId}&limit=20&order=popularity:desc`)
|
||||
// // .then(({ data }) => { res.status(200).send(data) })
|
||||
// // .catch(() => { res.send(400) });
|
||||
// });
|
||||
|
||||
exports.gameV2 = functions.https.onRequest((req, res) => {
|
||||
res.set('Access-Control-Allow-Origin', "*")
|
||||
|
||||
const { gameId } = req.query;
|
||||
|
||||
if (!gameId) {
|
||||
res.status(400).send('missing param gameId');
|
||||
}
|
||||
|
||||
const data = `fields *; where id = ${ gameId };`;
|
||||
|
||||
axios({
|
||||
url: 'https://api-v3.igdb.com/games',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'user-key': '3b516a46c3af209bb6e287e9090d720c'
|
||||
},
|
||||
data,
|
||||
})
|
||||
.then(({ data }) => { res.status(200).send(data) })
|
||||
.catch(() => { res.send(400) });
|
||||
});
|
||||
|
||||
exports.gamesV2 = functions.https.onRequest((req, res) => {
|
||||
res.set('Access-Control-Allow-Origin', "*")
|
||||
|
||||
const { gameId } = req.query;
|
||||
|
||||
if (!gameId) {
|
||||
res.status(400).send('missing param gameId');
|
||||
}
|
||||
|
||||
const data = `fields id,name,slug,rating,name,cover.url; where id = (${ gameId });`;
|
||||
|
||||
axios({
|
||||
url: 'https://api-v3.igdb.com/games',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'user-key': '3b516a46c3af209bb6e287e9090d720c'
|
||||
},
|
||||
data,
|
||||
})
|
||||
.then(({ data }) => { res.status(200).send(data) })
|
||||
.catch(() => { res.send(400) });
|
||||
});
|
||||
|
||||
|
||||
// TODO: merge search and game, swap out or request fields in FE
|
Loading…
Reference in a new issue