Skip to content
This repository has been archived by the owner on Mar 15, 2023. It is now read-only.

Commit

Permalink
Offline alert (#44)
Browse files Browse the repository at this point in the history
* add environment variable for disabling API communication

* apiDisabledJanuary2020
  • Loading branch information
lwojcik committed Dec 21, 2019
1 parent 2fc4870 commit 55fc003
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ API_LEGACY_BATTLENET_KEY=''
API_LEGACY_BATTLENET_SECRET=''
API_BATTLENET_KEY=''
API_BATTLENET_SECRET=''
API_BATTLENET_APIS_DISABLED='false'
API_TWITCH_EXTENSION_SHARED_SECRET=''
API_TWITCH_EXTENSION_CLIENT_ID=''
1 change: 1 addition & 0 deletions src/config/battlenet.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ const bnetConfig = {};
bnetConfig.apiKey = env.API_BATTLENET_KEY;
/** Battle.net API secret */
bnetConfig.apiSecret = env.API_BATTLENET_SECRET;
bnetConfig.apiDisabledJanuary2020 = env.API_BATTLENET_APIS_DISABLED_JANUARY_2020 === 'true';

module.exports = bnetConfig;
5 changes: 5 additions & 0 deletions src/routes/v1.1/config/get/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const fp = require('fastify-plugin');

const schema = require('./schema');

const bnetConfig = require('../../../../config/battlenet');

module.exports = fp(async (server, opts, next) => {
server.route({
url: '/v1.1/config/get/:channelId',
Expand All @@ -25,6 +27,7 @@ module.exports = fp(async (server, opts, next) => {
handler: async (request, reply) => {
try {
const { channelId } = request.params;
const { apiDisabledJanuary2020 } = bnetConfig;

const channelConfig = await server.db.models.ChannelConfig.findOne({ channelId });

Expand All @@ -43,12 +46,14 @@ module.exports = fp(async (server, opts, next) => {
realmId,
playerId,
selectedView,
apiDisabledJanuary2020,
});
}

return reply.code(404).send({
status: 404,
message: 'Account not found',
apiDisabledJanuary2020,
});
} catch (error) {
server.log.error(error);
Expand Down
2 changes: 2 additions & 0 deletions src/routes/v1.1/config/get/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ const responseJsonSchema = {
realmId: { type: 'number' },
playerId: { type: 'number' },
selectedView: { type: 'string' },
apiDisabledJanuary2020: { type: 'boolean' },
},
},
404: {
type: 'object',
properties: {
status: { type: 'number' },
message: { type: 'string' },
apiDisabledJanuary2020: { type: 'boolean' },
},
},
400: {
Expand Down
3 changes: 2 additions & 1 deletion src/routes/v1.1/viewer/get/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const fp = require('fastify-plugin');
const schema = require('./schema');

const redisConfig = require('../../../../config/redis');
// const bnetConfig = require('../../../../config/battlenet');

module.exports = fp(async (server, opts, next) => {
server.route({
Expand Down Expand Up @@ -37,7 +38,7 @@ module.exports = fp(async (server, opts, next) => {
server.log.info('generating and caching response...');
const channelConfigObject = await server.db.models.ChannelConfig.findOne({ channelId });

if (channelConfigObject && channelConfigObject._doc) { // eslint-disable-line no-underscore-dangle
if (channelConfigObject && channelConfigObject._doc) { // eslint-disable-line
const channelConfig = channelConfigObject._doc; // eslint-disable-line
const viewerData = await server.sc2pte.getViewerData(channelConfig);
const responseObject = {
Expand Down

0 comments on commit 55fc003

Please sign in to comment.