Skip to content

Commit

Permalink
add jsdoc generation
Browse files Browse the repository at this point in the history
  • Loading branch information
paulov-t committed Jun 3, 2022
1 parent fc864cd commit 7aaef1c
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 2,591 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#
out
## visual studio
.vscode
.vscode/sftp.json
Expand Down
2,569 changes: 0 additions & 2,569 deletions docs/Commands Explanation.md

This file was deleted.

100 changes: 85 additions & 15 deletions express/app.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
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');

// 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,
Expand Down Expand Up @@ -216,27 +226,87 @@ 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;
}
}
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) {
Expand Down
23 changes: 23 additions & 0 deletions jsdoc.json
Original file line number Diff line number Diff line change
@@ -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
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions src/Controllers/BotController.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Bot Controller.
* This controller contains everything to handle bot data and generation
*/
class BotController {

}
7 changes: 7 additions & 0 deletions src/Controllers/ConfigController.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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 = {};
Expand Down
18 changes: 12 additions & 6 deletions src/classes/move.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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];
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7aaef1c

Please sign in to comment.