From 55fc0031e614279272a0ad241b2a1c0f80d2c49e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20W=C3=B3jcik?= <1711174+lwojcik@users.noreply.github.com> Date: Sat, 21 Dec 2019 23:05:53 +0100 Subject: [PATCH] Offline alert (#44) * add environment variable for disabling API communication * apiDisabledJanuary2020 --- .env.sample | 1 + src/config/battlenet.js | 1 + src/routes/v1.1/config/get/index.js | 5 +++++ src/routes/v1.1/config/get/schema.js | 2 ++ src/routes/v1.1/viewer/get/index.js | 3 ++- 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.env.sample b/.env.sample index 680edd51..cf535779 100644 --- a/.env.sample +++ b/.env.sample @@ -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='' diff --git a/src/config/battlenet.js b/src/config/battlenet.js index fcf00488..0ae3afb0 100644 --- a/src/config/battlenet.js +++ b/src/config/battlenet.js @@ -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; diff --git a/src/routes/v1.1/config/get/index.js b/src/routes/v1.1/config/get/index.js index f3c31475..01c4b650 100644 --- a/src/routes/v1.1/config/get/index.js +++ b/src/routes/v1.1/config/get/index.js @@ -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', @@ -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 }); @@ -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); diff --git a/src/routes/v1.1/config/get/schema.js b/src/routes/v1.1/config/get/schema.js index 348d948f..207a75f0 100644 --- a/src/routes/v1.1/config/get/schema.js +++ b/src/routes/v1.1/config/get/schema.js @@ -25,6 +25,7 @@ const responseJsonSchema = { realmId: { type: 'number' }, playerId: { type: 'number' }, selectedView: { type: 'string' }, + apiDisabledJanuary2020: { type: 'boolean' }, }, }, 404: { @@ -32,6 +33,7 @@ const responseJsonSchema = { properties: { status: { type: 'number' }, message: { type: 'string' }, + apiDisabledJanuary2020: { type: 'boolean' }, }, }, 400: { diff --git a/src/routes/v1.1/viewer/get/index.js b/src/routes/v1.1/viewer/get/index.js index 6065edf3..0238cf66 100644 --- a/src/routes/v1.1/viewer/get/index.js +++ b/src/routes/v1.1/viewer/get/index.js @@ -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({ @@ -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 = {