diff --git a/.env.example b/.env.example index fc389f4dd..1a455025a 100644 --- a/.env.example +++ b/.env.example @@ -1,15 +1,4 @@ -MONGODB_URL='mongodb://127.0.0.1:27017/openWF' - -#DOCKER ONLY +# Docker may need a .env file for the following settings: DATABASE_PORT=27017 DATABASE_USERNAME=root DATABASE_PASSWORD=database -#DOCKER ONLY END - -# save logs to file -LOG_FILES=true -#possible log levels: { fatal: 0, error: 1, warn: 2, info: 3, http: 4, debug: 5, trace: 6 } -LOG_LEVEL=trace - - - diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 364b5f515..795b187a8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,4 +15,5 @@ jobs: with: node-version: "20.x" - run: npm ci + - run: cp config.json.example config.json - run: npm run build diff --git a/.gitignore b/.gitignore index 316e4fed5..0b1cf50b4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /build /.env +/config.json /static/data/*.bin yarn.lock /tmp diff --git a/config.json b/config.json.example similarity index 58% rename from config.json rename to config.json.example index d94fc3e71..757d8e7a0 100644 --- a/config.json +++ b/config.json.example @@ -1,8 +1,12 @@ { + "mongodbUrl": "mongodb://127.0.0.1:27017/openWF", + "logger": { + "files": true, + "level": "trace", + "__valid_levels": "fatal, error, warn, info, http, debug, trace" + }, + "myAddress": "localhost", "autoCreateAccount": true, - "buildLabel": "2024.05.03.11.35/g98E42og3EdWxS0UueO+PQ", - "matchmakingBuildId": "6945333874579955227", - "version": "35.5.11", "skipStoryModeChoice": true, "skipTutorial": true, "unlockAllScans": true, diff --git a/package-lock.json b/package-lock.json index 432ade5d4..acca05529 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,6 @@ "license": "GNU", "dependencies": { "copyfiles": "^2.4.1", - "dotenv": "^16.1.3", "express": "^5.0.0-beta.3", "mongoose": "^8.1.1", "warframe-items": "^1.1261.19", @@ -1493,17 +1492,6 @@ "node": ">=6.0.0" } }, - "node_modules/dotenv": { - "version": "16.1.3", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.1.3.tgz", - "integrity": "sha512-FYssxsmCTtKL72fGBSvb1K9dRz0/VZeWqFme/vSb7r7323x4CRaHu4LvQ5JG3+s6yt2YPbBrkpiEODktfyjI9A==", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/motdotla/dotenv?sponsor=1" - } - }, "node_modules/dynamic-dedupe": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/dynamic-dedupe/-/dynamic-dedupe-0.3.0.tgz", diff --git a/package.json b/package.json index 04654aa70..ba09cc40d 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "license": "GNU", "dependencies": { "copyfiles": "^2.4.1", - "dotenv": "^16.1.3", "express": "^5.0.0-beta.3", "mongoose": "^8.1.1", "warframe-items": "^1.1261.19", diff --git a/src/controllers/api/getCreditsController.ts b/src/controllers/api/getCreditsController.ts index 5f86de989..e7be097e1 100644 --- a/src/controllers/api/getCreditsController.ts +++ b/src/controllers/api/getCreditsController.ts @@ -1,5 +1,5 @@ import { RequestHandler } from "express"; -import config from "@/config.json"; +import { config } from "@/src/services/configService"; import { getInventory } from "@/src/services/inventoryService"; import { parseString } from "@/src/helpers/general"; diff --git a/src/controllers/api/getShipController.ts b/src/controllers/api/getShipController.ts index cc2794bfa..de89bdc18 100644 --- a/src/controllers/api/getShipController.ts +++ b/src/controllers/api/getShipController.ts @@ -1,5 +1,5 @@ import { RequestHandler } from "express"; -import config from "@/config.json"; +import { config } from "@/src/services/configService"; import allShipFeatures from "@/static/fixed_responses/allShipFeatures.json"; import { parseString } from "@/src/helpers/general"; import { getPersonalRooms } from "@/src/services/personalRoomsService"; diff --git a/src/controllers/api/inventoryController.ts b/src/controllers/api/inventoryController.ts index f3e08fef8..d3dddd2a7 100644 --- a/src/controllers/api/inventoryController.ts +++ b/src/controllers/api/inventoryController.ts @@ -2,7 +2,7 @@ import { toInventoryResponse } from "@/src/helpers/inventoryHelpers"; import { Inventory } from "@/src/models/inventoryModels/inventoryModel"; import { Request, RequestHandler, Response } from "express"; -import config from "@/config.json"; +import { config } from "@/src/services/configService"; import allMissions from "@/static/fixed_responses/allMissions.json"; import allQuestKeys from "@/static/fixed_responses/allQuestKeys.json"; import allShipDecorations from "@/static/fixed_responses/allShipDecorations.json"; diff --git a/src/controllers/api/loginController.ts b/src/controllers/api/loginController.ts index 4cd7f6ef8..17481713a 100644 --- a/src/controllers/api/loginController.ts +++ b/src/controllers/api/loginController.ts @@ -1,13 +1,14 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ import { RequestHandler } from "express"; -import config from "@/config.json"; +import { config } from "@/src/services/configService"; +import buildConfig from "@/static/data/buildConfig.json"; import { toLoginRequest } from "@/src/helpers/loginHelpers"; import { Account } from "@/src/models/loginModel"; import { createAccount, isCorrectPassword } from "@/src/services/loginService"; import { ILoginResponse } from "@/src/types/loginTypes"; -import { DTLS, groups, HUB, IRC, Nonce, NRS, platformCDNs } from "@/static/fixed_responses/login_static"; +import { DTLS, groups, HUB, Nonce, platformCDNs } from "@/static/fixed_responses/login_static"; import { logger } from "@/src/utils/logger"; // eslint-disable-next-line @typescript-eslint/no-misused-promises @@ -39,12 +40,12 @@ const loginController: RequestHandler = async (request, response) => { Groups: groups, platformCDNs: platformCDNs, Nonce: Nonce, - NRS: NRS, + NRS: [config.myAddress], DTLS: DTLS, - IRC: IRC, + IRC: [config.myAddress], HUB: HUB, - BuildLabel: config.buildLabel, - MatchmakingBuildId: config.matchmakingBuildId + BuildLabel: buildConfig.buildLabel, + MatchmakingBuildId: buildConfig.matchmakingBuildId }; response.json(newLoginResponse); @@ -68,12 +69,12 @@ const loginController: RequestHandler = async (request, response) => { Groups: groups, platformCDNs: platformCDNs, Nonce: Nonce, - NRS: NRS, + NRS: [config.myAddress], DTLS: DTLS, - IRC: IRC, + IRC: [config.myAddress], HUB: HUB, - BuildLabel: config.buildLabel, - MatchmakingBuildId: config.matchmakingBuildId + BuildLabel: buildConfig.buildLabel, + MatchmakingBuildId: buildConfig.matchmakingBuildId }; response.json(newLoginResponse); diff --git a/src/controllers/dynamic/worldStateController.ts b/src/controllers/dynamic/worldStateController.ts index 232e6e96d..32cfdfa07 100644 --- a/src/controllers/dynamic/worldStateController.ts +++ b/src/controllers/dynamic/worldStateController.ts @@ -1,11 +1,11 @@ import { RequestHandler } from "express"; import worldState from "@/static/fixed_responses/worldState.json"; -import config from "@/config.json"; +import buildConfig from "@/static/data/buildConfig.json"; const worldStateController: RequestHandler = (_req, res) => { res.json({ ...worldState, - BuildLabel: config.buildLabel, + BuildLabel: buildConfig.buildLabel, Time: Math.round(Date.now() / 1000) }); }; diff --git a/src/controllers/stats/viewController.ts b/src/controllers/stats/viewController.ts index c73eac38a..374c0d8ea 100644 --- a/src/controllers/stats/viewController.ts +++ b/src/controllers/stats/viewController.ts @@ -1,7 +1,7 @@ import { RequestHandler } from "express"; import { Inventory } from "@/src/models/inventoryModels/inventoryModel"; import { IStatsView } from "@/src/types/statTypes"; -import config from "@/config.json"; +import { config } from "@/src/services/configService"; import view from "@/static/fixed_responses/view.json"; import allScans from "@/static/fixed_responses/allScans.json"; diff --git a/src/routes/cache.ts b/src/routes/cache.ts index dba00602f..b714c648f 100644 --- a/src/routes/cache.ts +++ b/src/routes/cache.ts @@ -1,5 +1,5 @@ import express from "express"; -import config from "@/config.json"; +import buildConfig from "@/static/data/buildConfig.json"; const cacheRouter = express.Router(); @@ -12,7 +12,7 @@ cacheRouter.get("/B.Cache.Windows_en.bin*", (_req, res) => { }); cacheRouter.get(/^\/origin\/[a-zA-Z0-9]+\/[0-9]+\/H\.Cache\.bin.*$/, (_req, res) => { - res.sendFile(`static/data/H.Cache_${config.version}.bin`, { root: "./" }); + res.sendFile(`static/data/H.Cache_${buildConfig.version}.bin`, { root: "./" }); }); export { cacheRouter }; diff --git a/src/services/configService.ts b/src/services/configService.ts new file mode 100644 index 000000000..54d1e78d2 --- /dev/null +++ b/src/services/configService.ts @@ -0,0 +1,24 @@ +import rawConfig from "@/config.json"; + +interface IConfig { + mongodbUrl: string; + logger: ILoggerConfig; + myAddress: string; + autoCreateAccount?: boolean; + skipStoryModeChoice?: boolean; + skipTutorial?: boolean; + unlockAllScans?: boolean; + unlockAllMissions?: boolean; + unlockAllQuests?: boolean; + infiniteResources?: boolean; + unlockallShipFeatures?: boolean; + unlockAllShipDecorations?: boolean; + unlockAllFlavourItems?: boolean; +} + +interface ILoggerConfig { + files: boolean; + level: string; // "fatal" | "error" | "warn" | "info" | "http" | "debug" | "trace"; +} + +export const config: IConfig = rawConfig; diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 117891a4e..0d6852583 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -1,6 +1,6 @@ import { Inventory } from "@/src/models/inventoryModels/inventoryModel"; import new_inventory from "@/static/fixed_responses/postTutorialInventory.json"; -import config from "@/config.json"; +import { config } from "@/src/services/configService"; import { Types } from "mongoose"; import { ISuitClient } from "@/src/types/inventoryTypes/SuitTypes"; import { SlotNames } from "@/src/types/purchaseTypes"; diff --git a/src/services/mongoService.ts b/src/services/mongoService.ts index 0ef0c82d9..0c24c3ded 100644 --- a/src/services/mongoService.ts +++ b/src/services/mongoService.ts @@ -1,10 +1,8 @@ import { logger } from "@/src/utils/logger"; -import * as dotenv from "dotenv"; +import { config } from "@/src/services/configService"; import mongoose from "mongoose"; -dotenv.config(); - -const url = process.env.MONGODB_URL; +const url = config.mongodbUrl; if (url === undefined) { throw new Error("MONGODB_URL not found. Make sure you have a .env file in the root of the project!"); diff --git a/src/utils/logger.ts b/src/utils/logger.ts index c1bfbc696..03aa25626 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -1,11 +1,9 @@ import { createLogger, format, transports, Logger, LeveledLogMethod, addColors } from "winston"; import "winston-daily-rotate-file"; -import * as dotenv from "dotenv"; +import { config } from "@/src/services/configService"; import * as util from "util"; import { isEmptyObject } from "@/src/helpers/general"; -dotenv.config(); - // const combineMessageAndSplat = () => { // return { // transform: (info: any, _opts: any) => { @@ -72,7 +70,7 @@ const consoleLog = new transports.Console({ ) }); -const transportOptions = process.env.LOG_FILES === "true" ? [consoleLog, errorLog, combinedLog] : [consoleLog]; +const transportOptions = config.logger.files ? [consoleLog, errorLog, combinedLog] : [consoleLog]; //possible log levels: { fatal: 0, error: 1, warn: 2, info: 3, http: 4, debug: 5, trace: 6 }, const logLevels = { @@ -98,7 +96,7 @@ const logLevels = { export const logger = createLogger({ levels: logLevels.levels, - level: process.env.LOG_LEVEL, + level: config.logger.level, defaultMeta: { version: process.env.npm_package_version }, transports: transportOptions }) as Logger & Record; diff --git a/static/data/.gitkeep b/static/data/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/static/data/buildConfig.json b/static/data/buildConfig.json new file mode 100644 index 000000000..5f827cfdd --- /dev/null +++ b/static/data/buildConfig.json @@ -0,0 +1,5 @@ +{ + "version": "35.5.11", + "buildLabel": "2024.05.03.11.35/g98E42og3EdWxS0UueO+PQ", + "matchmakingBuildId": "6945333874579955227" +} diff --git a/static/data/items.ts b/static/data/items.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/static/fixed_responses/login_static.ts b/static/fixed_responses/login_static.ts index d5b3ede91..ef6213a94 100644 --- a/static/fixed_responses/login_static.ts +++ b/static/fixed_responses/login_static.ts @@ -24,10 +24,6 @@ export const platformCDNs = [ export const Nonce = 1231231233; -export const NRS = ["localhost"]; - export const DTLS = 99; -export const IRC = ["localhost"]; - export const HUB = "https://arbiter.warframe.com/api/";