2018-10-19 05:15:28 +00:00
|
|
|
const functions = require('firebase-functions');
|
|
|
|
const axios = require('axios');
|
|
|
|
|
2019-06-09 02:04:07 +00:00
|
|
|
axios.defaults.headers.common['user-key'] = functions.config().igdbv3.key;
|
2018-10-19 05:15:28 +00:00
|
|
|
|
|
|
|
exports.search = functions.https.onRequest((req, res) => {
|
2018-10-19 06:00:49 +00:00
|
|
|
res.set('Access-Control-Allow-Origin', "*")
|
|
|
|
|
2019-06-09 02:04:07 +00:00
|
|
|
const { search, platform } = req.query;
|
2019-04-02 23:42:43 +00:00
|
|
|
|
2019-06-09 02:04:07 +00:00
|
|
|
const data = `search "${search}"; fields id,name,slug,rating,name,cover.image_id; where platforms = (${platform});`
|
2019-04-02 23:42:43 +00:00
|
|
|
|
|
|
|
axios({
|
2019-06-09 02:04:07 +00:00
|
|
|
url: 'https://api-v3.igdb.com/games',
|
2019-04-02 23:42:43 +00:00
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Accept': 'application/json',
|
|
|
|
},
|
|
|
|
data,
|
|
|
|
})
|
|
|
|
.then(({ data }) => { res.status(200).send(data) })
|
2019-06-09 02:04:07 +00:00
|
|
|
.catch((error) => { res.send(error) });
|
2019-04-02 23:42:43 +00:00
|
|
|
});
|
|
|
|
|
2019-06-09 02:04:07 +00:00
|
|
|
exports.games = functions.https.onRequest((req, res) => {
|
2018-10-25 06:33:15 +00:00
|
|
|
res.set('Access-Control-Allow-Origin', "*")
|
|
|
|
|
2019-06-09 02:04:07 +00:00
|
|
|
const { games } = req.query;
|
2018-10-25 06:33:15 +00:00
|
|
|
|
2019-06-09 02:04:07 +00:00
|
|
|
if (!games) {
|
|
|
|
res.status(400).send('missing param games');
|
|
|
|
}
|
|
|
|
|
|
|
|
const data = `fields id,name,slug,rating,name,cover.image_id; where id = (${ games });`;
|
2019-04-25 18:46:25 +00:00
|
|
|
|
|
|
|
axios({
|
|
|
|
url: 'https://api-v3.igdb.com/games',
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Accept': 'application/json',
|
|
|
|
},
|
|
|
|
data,
|
|
|
|
})
|
|
|
|
.then(({ data }) => { res.status(200).send(data) })
|
2019-06-09 02:04:07 +00:00
|
|
|
.catch((error) => { res.send(error) });
|
2019-04-25 18:46:25 +00:00
|
|
|
});
|
|
|
|
|
2019-06-09 02:04:07 +00:00
|
|
|
exports.game = functions.https.onRequest((req, res) => {
|
2019-04-25 18:46:25 +00:00
|
|
|
res.set('Access-Control-Allow-Origin', "*")
|
|
|
|
|
|
|
|
const { gameId } = req.query;
|
|
|
|
|
|
|
|
if (!gameId) {
|
|
|
|
res.status(400).send('missing param gameId');
|
|
|
|
}
|
|
|
|
|
2019-06-09 02:04:07 +00:00
|
|
|
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,
|
2019-08-20 06:19:42 +00:00
|
|
|
platforms.id,
|
2019-06-09 02:04:07 +00:00
|
|
|
game_modes.name,
|
|
|
|
time_to_beat;
|
|
|
|
|
|
|
|
where id = ${ gameId };`;
|
2019-04-25 18:46:25 +00:00
|
|
|
|
|
|
|
axios({
|
|
|
|
url: 'https://api-v3.igdb.com/games',
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Accept': 'application/json',
|
|
|
|
},
|
|
|
|
data,
|
|
|
|
})
|
2018-10-25 06:33:15 +00:00
|
|
|
.then(({ data }) => { res.status(200).send(data) })
|
2019-06-09 02:04:07 +00:00
|
|
|
.catch((error) => { res.send(error) });
|
2018-10-25 06:33:15 +00:00
|
|
|
});
|
2019-04-25 18:46:25 +00:00
|
|
|
|
2019-06-09 02:04:07 +00:00
|
|
|
exports.email = functions.https.onRequest((req, res) => {
|
2019-04-25 18:46:25 +00:00
|
|
|
res.set('Access-Control-Allow-Origin', "*")
|
|
|
|
|
2019-06-09 02:04:07 +00:00
|
|
|
const { template_id, address } = req.query;
|
2019-04-25 18:46:25 +00:00
|
|
|
|
2019-06-09 02:04:07 +00:00
|
|
|
if (!template_id || !address) {
|
|
|
|
res.send(400);
|
2019-04-25 18:46:25 +00:00
|
|
|
}
|
|
|
|
|
2019-06-09 02:04:07 +00:00
|
|
|
const data = {
|
|
|
|
recipients: [
|
|
|
|
{ address },
|
|
|
|
],
|
|
|
|
content: { template_id },
|
|
|
|
};
|
2019-04-25 18:46:25 +00:00
|
|
|
|
|
|
|
axios({
|
2019-06-09 02:04:07 +00:00
|
|
|
url: 'https://api.sparkpost.com/api/v1/transmissions',
|
2019-04-25 18:46:25 +00:00
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
2019-06-09 02:04:07 +00:00
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
2019-04-25 18:46:25 +00:00
|
|
|
'Accept': 'application/json',
|
2019-06-09 02:04:07 +00:00
|
|
|
'Authorization': functions.config().sparkpost.key,
|
2019-04-25 18:46:25 +00:00
|
|
|
},
|
|
|
|
data,
|
|
|
|
})
|
|
|
|
.then(({ data }) => { res.status(200).send(data) })
|
2019-06-09 02:04:07 +00:00
|
|
|
.catch((error) => { res.send(error) });
|
2019-04-25 18:46:25 +00:00
|
|
|
});
|