diff --git a/src/config-manager.ts b/src/config-manager.ts index 125002e..616254f 100644 --- a/src/config-manager.ts +++ b/src/config-manager.ts @@ -31,7 +31,8 @@ if (process.env.PN_BOSS_CONFIG_MONGOOSE_CONNECT_OPTIONS_PATH?.trim()) { } export const disabledFeatures: DisabledFeatures = { - s3: false + s3: false, + spr: false }; export const config: Config = { @@ -78,6 +79,9 @@ export const config: Config = { secret: process.env.PN_BOSS_CONFIG_S3_ACCESS_SECRET?.trim() || '' }, disk_path: process.env.PN_BOSS_CONFIG_CDN_DISK_PATH?.trim() || '' + }, + spr: { + enabled: process.env.PN_BOSS_CONFIG_STREETPASS_RELAY_ENABLED?.trim().toLowerCase() === 'true' } }; @@ -174,6 +178,15 @@ if (!config.cdn.s3.secret) { disabledFeatures.s3 = true; } +if (!config.spr.enabled) { + warnings.push('PN_BOSS_CONFIG_STREETPASS_RELAY_ENABLED is not set or disabled. Disabling feature. To enable feature set the PN_BOSS_CONFIG_STREETPASS_RELAY_ENABLED environment variable'); + disabledFeatures.spr = true; +} + +if (config.spr.enabled) { + disabledFeatures.spr = false; +} + if (disabledFeatures.s3) { if (!config.cdn.disk_path) { errors.push('s3 file storage is disabled and no CDN disk path was set. Set the PN_BOSS_CONFIG_CDN_DISK_PATH environment variable'); diff --git a/src/services/nppl.ts b/src/services/nppl.ts index 7429843..928ee98 100644 --- a/src/services/nppl.ts +++ b/src/services/nppl.ts @@ -2,6 +2,7 @@ import xmlbuilder from 'xmlbuilder'; import moment from 'moment'; import express from 'express'; import subdomain from 'express-subdomain'; +import { disabledFeatures } from '@/config-manager'; import type { PolicyList } from '@/types/common/policylist'; const nppl = express.Router(); @@ -39,61 +40,110 @@ function get3DSPolicyList(countryCode: string, majorVersion: string): { PolicyLi return null; } - // TODO - Pull this from the DB and use the country code - return { - PolicyList: { - MajorVersion: Number(majorVersion), - MinorVersion: 0, - ListId: 1891, - DefaultStop: false, - ForceVersionUp: false, - UpdateTime: moment().utc().format('YYYY-MM-DDTHH:MM:SS+0000'), - Priority: [ - { - TitleId: '0004003000008f02', - TaskId: 'basho0', - Level: 'HIGH', - Persistent: true, // TODO - What's this? - Revive: true // TODO - What's this? - }, - { - TitleId: '000400300000bc00', - TaskId: 'OlvNotf', - Level: 'HIGH', - Persistent: true, // TODO - What's this? - Revive: true // TODO - What's this? - }, - { - TitleId: '000400300000bd00', - TaskId: 'OlvNotf', - Level: 'HIGH', - Persistent: true, // TODO - What's this? - Revive: true // TODO - What's this? - }, - { - TitleId: '000400300000be00', - TaskId: 'OlvNotf', - Level: 'HIGH', - Persistent: true, // TODO - What's this? - Revive: true // TODO - What's this? - }, - { - TitleId: '0004003000008f02', - TaskId: 'pl', - Level: 'HIGH', - Persistent: true, // TODO - What's this? - Revive: true // TODO - What's this? - }, - { - TitleId: '0004013000003400', - TaskId: 'sprelay', - Level: 'HIGH', - Persistent: true, // TODO - What's this? - Revive: true // TODO - What's this? - } - ] - } - }; + if (!disabledFeatures.spr) { + return { + PolicyList: { + MajorVersion: Number(majorVersion), + MinorVersion: 0, + ListId: 1891, + DefaultStop: false, + ForceVersionUp: false, + UpdateTime: moment().utc().format('YYYY-MM-DDTHH:MM:SS+0000'), + Priority: [ + { + TitleId: '0004003000008f02', + TaskId: 'basho0', + Level: 'HIGH', + Persistent: true, // TODO - What's this? + Revive: true // TODO - What's this? + }, + { + TitleId: '000400300000bc00', + TaskId: 'OlvNotf', + Level: 'HIGH', + Persistent: true, // TODO - What's this? + Revive: true // TODO - What's this? + }, + { + TitleId: '000400300000bd00', + TaskId: 'OlvNotf', + Level: 'HIGH', + Persistent: true, // TODO - What's this? + Revive: true // TODO - What's this? + }, + { + TitleId: '000400300000be00', + TaskId: 'OlvNotf', + Level: 'HIGH', + Persistent: true, // TODO - What's this? + Revive: true // TODO - What's this? + }, + { + TitleId: '0004003000008f02', + TaskId: 'pl', + Level: 'HIGH', + Persistent: true, // TODO - What's this? + Revive: true // TODO - What's this? + }, + { + TitleId: '0004013000003400', + TaskId: 'sprelay', + Level: 'HIGH', + Persistent: true, // TODO - What's this? + Revive: true // TODO - What's this? + } + ] + } + }; + } else { + return { + PolicyList: { + MajorVersion: Number(majorVersion), + MinorVersion: 0, + ListId: 1891, + DefaultStop: false, + ForceVersionUp: false, + UpdateTime: moment().utc().format('YYYY-MM-DDTHH:MM:SS+0000'), + Priority: [ + { + TitleId: '0004003000008f02', + TaskId: 'basho0', + Level: 'HIGH', + Persistent: true, // TODO - What's this? + Revive: true // TODO - What's this? + }, + { + TitleId: '000400300000bc00', + TaskId: 'OlvNotf', + Level: 'HIGH', + Persistent: true, // TODO - What's this? + Revive: true // TODO - What's this? + }, + { + TitleId: '000400300000bd00', + TaskId: 'OlvNotf', + Level: 'HIGH', + Persistent: true, // TODO - What's this? + Revive: true // TODO - What's this? + }, + { + TitleId: '000400300000be00', + TaskId: 'OlvNotf', + Level: 'HIGH', + Persistent: true, // TODO - What's this? + Revive: true // TODO - What's this? + }, + { + TitleId: '0004003000008f02', + TaskId: 'pl', + Level: 'HIGH', + Persistent: true, // TODO - What's this? + Revive: true // TODO - What's this? + } + ] + } + }; + } } function getWiiUPolicyList(countryCode: string, majorVersion: string): { PolicyList: PolicyList } | null { diff --git a/src/types/common/config.ts b/src/types/common/config.ts index 021d197..e677d2a 100644 --- a/src/types/common/config.ts +++ b/src/types/common/config.ts @@ -2,6 +2,7 @@ import type mongoose from 'mongoose'; export interface DisabledFeatures { s3: boolean; + spr: boolean; } export interface Config { @@ -49,4 +50,7 @@ export interface Config { }; disk_path: string; }; + spr: { + enabled: boolean; + }; }