mirror of
https://github.com/romancm/gamebrary
synced 2024-11-24 12:13:08 +00:00
c2823c2a59
* Updated endpoints to use IGDB v3 * Updated computed props to match v3 changes * Moved ageRatings to getter + updated for v3 * Updated getters to support v3 changes * Moved all ratings images under same folder * Use new endpoints in actions * Compatibility updates * Null check * formatting * Load games in chunks of 10 to meet new API requirements * More compatibility changes * Use ids for New and standard 3DS, great job naming consoles nintendo! * Drop v2 suffix
120 lines
3 KiB
JavaScript
Executable file
120 lines
3 KiB
JavaScript
Executable file
const functions = require('firebase-functions');
|
|
const axios = require('axios');
|
|
|
|
axios.defaults.headers.common['user-key'] = functions.config().igdbv3.key;
|
|
|
|
exports.search = functions.https.onRequest((req, res) => {
|
|
res.set('Access-Control-Allow-Origin', "*")
|
|
|
|
const { search, platform } = req.query;
|
|
|
|
const data = `search "${search}"; fields id,name,slug,rating,name,cover.image_id; where platforms = (${platform});`
|
|
|
|
axios({
|
|
url: 'https://api-v3.igdb.com/games',
|
|
method: 'POST',
|
|
headers: {
|
|
'Accept': 'application/json',
|
|
},
|
|
data,
|
|
})
|
|
.then(({ data }) => { res.status(200).send(data) })
|
|
.catch((error) => { res.send(error) });
|
|
});
|
|
|
|
exports.games = functions.https.onRequest((req, res) => {
|
|
res.set('Access-Control-Allow-Origin', "*")
|
|
|
|
const { games } = req.query;
|
|
|
|
if (!games) {
|
|
res.status(400).send('missing param games');
|
|
}
|
|
|
|
const data = `fields id,name,slug,rating,name,cover.image_id; where id = (${ games });`;
|
|
|
|
axios({
|
|
url: 'https://api-v3.igdb.com/games',
|
|
method: 'POST',
|
|
headers: {
|
|
'Accept': 'application/json',
|
|
},
|
|
data,
|
|
})
|
|
.then(({ data }) => { res.status(200).send(data) })
|
|
.catch((error) => { res.send(error) });
|
|
});
|
|
|
|
exports.game = 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
|
|
name,
|
|
summary,
|
|
cover.image_id,
|
|
screenshots.image_id,
|
|
player_perspectives.name,
|
|
involved_companies.company.name,
|
|
involved_companies.developer,
|
|
involved_companies.publisher,
|
|
release_dates.platform,
|
|
release_dates.date,
|
|
websites.category,
|
|
websites.url,
|
|
age_ratings.*,
|
|
videos.video_id,
|
|
rating,
|
|
genres.name,
|
|
platforms.name,
|
|
game_modes.name,
|
|
time_to_beat;
|
|
|
|
where id = ${ gameId };`;
|
|
|
|
axios({
|
|
url: 'https://api-v3.igdb.com/games',
|
|
method: 'POST',
|
|
headers: {
|
|
'Accept': 'application/json',
|
|
},
|
|
data,
|
|
})
|
|
.then(({ data }) => { res.status(200).send(data) })
|
|
.catch((error) => { res.send(error) });
|
|
});
|
|
|
|
exports.email = functions.https.onRequest((req, res) => {
|
|
res.set('Access-Control-Allow-Origin', "*")
|
|
|
|
const { template_id, address } = req.query;
|
|
|
|
if (!template_id || !address) {
|
|
res.send(400);
|
|
}
|
|
|
|
const data = {
|
|
recipients: [
|
|
{ address },
|
|
],
|
|
content: { template_id },
|
|
};
|
|
|
|
axios({
|
|
url: 'https://api.sparkpost.com/api/v1/transmissions',
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
'Accept': 'application/json',
|
|
'Authorization': functions.config().sparkpost.key,
|
|
},
|
|
data,
|
|
})
|
|
.then(({ data }) => { res.status(200).send(data) })
|
|
.catch((error) => { res.send(error) });
|
|
});
|