From 7aaef1c8ee5305d7ab3631c4be600a56c842c996 Mon Sep 17 00:00:00 2001 From: PARGSoft Date: Fri, 3 Jun 2022 14:55:25 +0100 Subject: [PATCH] add jsdoc generation --- .gitignore | 2 + docs/Commands Explanation.md | 2569 --------------------------- express/app.js | 100 +- jsdoc.json | 23 + package.json | 4 +- src/Controllers/BotController.js | 4 + src/Controllers/ConfigController.js | 7 + src/classes/move.js | 18 +- 8 files changed, 136 insertions(+), 2591 deletions(-) delete mode 100644 docs/Commands Explanation.md create mode 100644 jsdoc.json diff --git a/.gitignore b/.gitignore index 42065c76..4d73df23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +# +out ## visual studio .vscode .vscode/sftp.json diff --git a/docs/Commands Explanation.md b/docs/Commands Explanation.md deleted file mode 100644 index e8680d4a..00000000 --- a/docs/Commands Explanation.md +++ /dev/null @@ -1,2569 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - JET-Backend-Server/Commands Explanation.md at 5845559ee8dbf73d676030a0f276a9c229d5c8d5 · JustEmuTarkov/JET-Backend-Server - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Skip to content - - - - - - - - - - - -
- -
- - - - - - - -
- - - -
- - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - -
- -
- - - - JustEmuTarkov  /   - JET-Backend-Server  /   - -
-
- - - -
- - -
- - -
- - - - Type # for issues and pull requests, > for commands, and ? for help - - - Type # for issues, pull requests, and projects, > for commands, and ? for help - - - Type # for issues, pull requests, and projects, / for files, and > for commands - - -
- -
-
- We’ve encountered an error and some results aren't available at this time. Type a new search or try again later. -
-
- - No results matched your search - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - Search for issues and pull requests - - # - - - - Search for issues, pull requests, discussions, and projects - - # - - - - Search for organizations, repositories, and users - - @ - - - - Search for projects - - ! - - - - Search for files - - / - - - - Activate command mode - - > - - - - Search your issues, pull requests, and discussions - - # author:@me - - - - Search your issues, pull requests, and discussions - - # author:@me - - - - Filter to pull requests - - # is:pr - - - - Filter to issues - - # is:issue - - - - Filter to discussions - - # is:discussion - - - - Filter to projects - - # is:project - - - - Filter to open issues, pull requests, and discussions - - # is:open - - - - - - - - - - - - - - - - -
-
-
- -
- - - - - - - - - - -
- - - - -
-
-
- - - - - - - - - - - - -
- -
- -
-

- - - / - - JET-Backend-Server - - - Private -

- -
- -
    - - - -
  • - -
    - - - - - - - Watch - - - 5 - - - -
    -
    -

    Notifications

    - -
    - -
    -
    - - - - - - - - -
    - - -
    -
    -
    - - - - -
    -
    -
    - - - -
  • - -
  • - -
  • - -
  • - - -
    -
    - - -
    -
    - -
    -
    - - - - - -
    - -
    -
    - - - - - - - -
    - -
    -
    -
    -
    -
    -
  • - -
  • - - -
  • -
- -
- -
-
- - - - -
- - - -
-
- - Open in github.dev - Open in a new github.dev tab - - - - - - - -
- - - - - Permalink - - -
- -
-
- - - 5845559ee8 - - - - -
-
-
- Switch branches/tags - -
- - - -
- -
- -
- - -
- -
- - - - - - - - - - - - - - - - -
- - -
-
-
-
- -
- -
- - - - Go to file - - -
- - - - -
-
-
- - - - - - - - -
- -
-
-
 
-
- -
-
 
- Cannot retrieve contributors at this time -
-
- - - - - - - - - - - -
- -
- - -
- - 26 lines (21 sloc) - - 1.34 KB -
- -
- - - - - -
- - - - - - - - - - - - - - - - - - - -
-
- -
- -
-
- - -
-

Console Command List

-

All commands need to be typed inside server console with confirmation of button "Enter"

-
    -
  • -

    Register new account
    -/register login edition password
    -login -> allows only alphanumeric values (spaces are forbidden)
    -edition -> choose editions by typing number of edition you want (1 - Prepare To Escape, 2 - Left Behind, 3 - Edge Of Darkness, by default its set to standard account) (Not Required)
    -password -> password allows all characters except spaces (Not Required)
    -to login you dont need password which means it can be empty

    -
  • -
  • -

    Adding item to profile
    -/addItem MySession TemplateId Amount
    -MySession -> Session id of the profile (if you dont know where to find it open Profiles folder in server and name of the folder is session id)
    -TemplateId -> Its a template id of item you want to spawn (you can check id's here: https://eft.justemutarkov.eu/)
    -Amount -> Amount of items to spawn inside inventory

    -
  • -
  • -

    Set Debug Session id -this option is used to test requests using web browser without setting the session id
    -/devSession switch SessionId
    -switch -> value true or false to enable or disable this option
    -SessionId -> Value need to be a existing session id of the profile

    -
  • -
  • -

    Soft Restart the server
    -softly restarts the server variables
    -/restart

    -
  • -
-
-
- -
- - - - -
- - -
- - -
-
- - - - -
- - - -
-
- -
-
- -
- - - - - - - - - - - - - - - - - - - - - - diff --git a/express/app.js b/express/app.js index 8a00998f..b2aafd68 100644 --- a/express/app.js +++ b/express/app.js @@ -1,19 +1,20 @@ -var createError = require('http-errors'); -var express = require('express'); -var path = require('path'); +const createError = require('http-errors'); +const express = require('express'); +const path = require('path'); const { Http2ServerRequest } = require('http2'); const http = require('http'); const utility = require('./../core/util/utility') const { ResponseController, Routes } = require('./../src/Controllers/ResponseController'); const { TarkovSend } = require('./../core/server/tarkovSend'); const zlib = require('zlib'); -var compression = require('compression'); +const compression = require('compression'); +const fs = require('fs'); const responseClass = require("./../src/functions/response").responses; const legacyCallbacks = require("./../src/functions/callbacks.js").callbacks const cookieParser = require('cookie-parser'); -const { truncate } = require('fs'); +const { truncate, fstat } = require('fs'); const { logger } = require('../core/util/logger'); // var logger = require('morgan'); @@ -21,13 +22,22 @@ const { logger } = require('../core/util/logger'); // var indexRouter = require('./routes/index'); // var usersRouter = require('./routes/users'); -var app = express(); +const app = express(); // view engine setup app.set('views', path.join(__dirname, 'views')); -app.set('view engine', 'ejs'); +// // app.set('view engine', 'ejs'); +// app.set('docs', path.join(__dirname, 'out')); +// app.set('out', path.join(__dirname, 'out')); +// app.engine('html', require('ejs').renderFile); +// app.set('view engine', 'html'); +app.set('view engine', 'html'); +app.engine('html', require('ejs').renderFile); +// app.set('out', process.cwd() + "/out/"); +// console.log(process.cwd() + "\\out\\"); +// app.use(express.static(process.cwd() + "\\out\\")); app.use(express.raw({ type: "application/json", limit: '50mb', parameterLimit: 100000, @@ -216,14 +226,73 @@ for(const r in responseClass.staticResponses) { }); } +/** + * Add support for JSDoc directory output + * You can rebuild the docs by running jsdoc src/ -r . in the Terminal + */ +app.use(function(req, res, next) { + + if(req.url.includes("/docs/") || req.url.includes("/out/")) { + + let finalFile = req.url.split('/')[req.url.split('/').length-1]; + // console.log(finalFile); + if(finalFile === "" || finalFile === undefined) + finalFile = "index.html"; + const requestedPath = req.url.replace("/out/", "").replace("/docs/", "").replace(finalFile, "").replace("/", "\\").replace("\/", "\\"); + // console.log(requestedPath); + + const docsPath = process.cwd() + "\\out\\" + requestedPath; + // console.log(docsPath); + const files = fs.readdirSync(docsPath); + // console.log(files); + + for(const file of files) { + // console.log(file); + if(finalFile.toLowerCase().includes(file.toLowerCase())) { + let readFile = fs.readFileSync(docsPath + finalFile); + + switch(finalFile.split('.')[finalFile.split('.').length-1]) { + case "js": + res.contentType("text/js"); + break; + case "html": + res.contentType("text/html"); + break; + case "css": + res.contentType("text/css"); + break; + case "woff": + res.contentType("font/woff"); + break; + + } + res.status(200).send(readFile.toString()); + return; + } + + } + res.status(404).send(); + // for(const r in responseClass.dynamicResponses) { + // if (req.url.includes(r)) { + // // if (req.url === r || req.url.endsWith(r)) { + // // console.log("found dynamic route!"); + // // console.log(req); + // // console.log(res); + // // console.log(responseClass.dynamicResponses[r]); + // handleRoute(req, res, responseClass.dynamicResponses[r]); + // return; + // } + // } + } + next(); +}); + +/** + * Handle "Dynamic" responses (Files, Bundles, Traders etc) + */ app.use(function(req, res, next) { for(const r in responseClass.dynamicResponses) { if (req.url.includes(r)) { - // if (req.url === r || req.url.endsWith(r)) { - // console.log("found dynamic route!"); - // console.log(req); - // console.log(res); - // console.log(responseClass.dynamicResponses[r]); handleRoute(req, res, responseClass.dynamicResponses[r]); return; } @@ -231,12 +300,13 @@ app.use(function(req, res, next) { next(); }); -app.get('/', (req,res) => { +/** + * Home Page - NOT USED + */ +app.get('/', (req,res) => { res.status(200).send("EXPRESS Tarkov API up and running!"); }); -// app.use('/', indexRouter); -// app.use('/users', usersRouter); // catch 404 and forward to error handler app.use(function(req, res, next) { diff --git a/jsdoc.json b/jsdoc.json new file mode 100644 index 00000000..4ce03fb9 --- /dev/null +++ b/jsdoc.json @@ -0,0 +1,23 @@ +{ + "tags": { + "allowUnknownTags": false + }, + "source": { + "include": "src/.", + "includePattern": "\\.js$", + "excludePattern": "(node_modules/|docs)" + }, + "plugins": [ + "plugins/markdown" + ], + "opts": { + "encoding": "utf8", + "destination": "docs/", + "recurse": true, + "verbose": true + }, + "templates": { + "cleverLinks": false, + "monospaceLinks": false + } +} \ No newline at end of file diff --git a/package.json b/package.json index 0556dbb2..f0e1464e 100644 --- a/package.json +++ b/package.json @@ -4,13 +4,15 @@ "author": "AE-Team, JET Team, Paulov", "license": "MIT", "scripts": { - "start": "node bin/www.js" + "start": "node bin/www.js", + "generate-docs": "jsdoc -r ." }, "dependencies": { "compression": "^1.7.4", "cookie-parser": "^1.4.6", "crypto": "^1.0.1", "decimal-adjust": "^0.0.0", + "docdash": "^1.2.0", "ejs": "^3.1.7", "express": "^4.18.1", "selfsigned": "^2.0.1", diff --git a/src/Controllers/BotController.js b/src/Controllers/BotController.js index b15febc6..a8853095 100644 --- a/src/Controllers/BotController.js +++ b/src/Controllers/BotController.js @@ -1,3 +1,7 @@ +/** + * Bot Controller. + * This controller contains everything to handle bot data and generation + */ class BotController { } \ No newline at end of file diff --git a/src/Controllers/ConfigController.js b/src/Controllers/ConfigController.js index 42a6ccb7..536c09f6 100644 --- a/src/Controllers/ConfigController.js +++ b/src/Controllers/ConfigController.js @@ -1,5 +1,9 @@ const fs = require('fs'); +/** + * Config Controller. + * This controller provides direct access to all the config json files found in user/configs + */ class ConfigController { constructor() { ConfigController.rebuildFromBaseConfigs(); @@ -8,6 +12,9 @@ class ConfigController { static Instance = new ConfigController(); static Configs = {}; + /** + * Fills ConfigController.Configs with parsed JSON data from user/configs directory + */ static rebuildFromBaseConfigs() { if(ConfigController.Configs === undefined) ConfigController.Configs = {}; diff --git a/src/classes/move.js b/src/classes/move.js index 5a53ce84..d9919147 100644 --- a/src/classes/move.js +++ b/src/classes/move.js @@ -50,7 +50,7 @@ function getOwnerInventoryItems(body, sessionID) { * @param {*} pmcData * @param {*} body * @param {*} sessionID - * @returns + * @returns {object} */ function moveItem(pmcData, body, sessionID) { const output = item_f.handler.getOutput(sessionID); @@ -65,6 +65,12 @@ function moveItem(pmcData, body, sessionID) { return output; } +/** + * + * @param {*} pmcData + * @param {*} body + * @param {*} sessionID + */ module.exports.applyInventoryChanges = (pmcData, body, sessionID) => { //const output = item_f.handler.getOutput(sessionID); @@ -218,7 +224,7 @@ function removeItemFromProfile(pmcData, itemId, sessionID) { } // set output if necessary. - if (typeof sessionID != "undefined" && output.hasOwnProperty("profileChanges")) { + if (sessionID !== undefined && output.hasOwnProperty("profileChanges")) { item_f.handler.setOutput(output); } } @@ -228,7 +234,7 @@ function removeItemFromProfile(pmcData, itemId, sessionID) { * @param {*} profileData * @param {*} body * @param {*} sessionID - * @returns + * @returns {object} */ function removeItem(profileData, body, sessionID) { let toDo = [body]; @@ -247,7 +253,7 @@ function removeItem(profileData, body, sessionID) { * @param {*} pmcData * @param {*} body * @param {*} sessionID - * @returns + * @returns {object} */ function discardItem(pmcData, body, sessionID) { insurance_f.handler.remove(pmcData, body.item, sessionID); @@ -260,7 +266,7 @@ function discardItem(pmcData, body, sessionID) { * @param {Object} pmcData * @param {Object} body * @param {string} sessionID - * @returns + * @returns {object} */ function splitItem(pmcData, body, sessionID) { const output = item_f.handler.getOutput(sessionID); @@ -318,7 +324,7 @@ function splitItem(pmcData, body, sessionID) { * @param {Object} pmcData - PMC Part of profile * @param {Object} body - Request Body * @param {string} sessionID - Session ID - * @returns response + * @returns {object} */ function mergeItem(pmcData, body, sessionID) { const output = item_f.handler.getOutput(sessionID);