Skip to content

Commit

Permalink
Updated the comment format & Removed settings file
Browse files Browse the repository at this point in the history
  • Loading branch information
MKHenson committed Oct 17, 2016
1 parent e1b32ad commit 5611734
Show file tree
Hide file tree
Showing 28 changed files with 845 additions and 1,060 deletions.
6 changes: 0 additions & 6 deletions .vscode/settings.json

This file was deleted.

49 changes: 17 additions & 32 deletions src/controllers/comments-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import * as winston from "winston";
import { okJson, errJson } from "../serializers";

/**
* A controller that deals with the management of comments
*/
* A controller that deals with the management of comments
*/
export default class CommentsController extends Controller {
/**
* Creates a new instance of the controller
* @param {IServer} server The server configuration options
* @param {IConfig} config The configuration options
* @param {express.Express} e The express instance of this server
*/
* Creates a new instance of the controller
* @param server The server configuration options
* @param config The configuration options
* @param e The express instance of this server
*/
constructor( server: mp.IServer, config: mp.IConfig, e: express.Express ) {
super( [ Model.registerModel( CommentsModel ) ] );

Expand All @@ -45,11 +45,8 @@ export default class CommentsController extends Controller {
}

/**
* Returns an array of IComment items
* @param {mp.IAuthReq} req
* @param {express.Response} res
* @param {Function} next
*/
* Returns an array of IComment items
*/
private async getComments( req: mp.IAuthReq, res: express.Response, next: Function ) {
var comments = this.getModel( "comments" );
var that = this;
Expand Down Expand Up @@ -145,11 +142,8 @@ export default class CommentsController extends Controller {
}

/**
* Returns a single comment
* @param {mp.IAuthReq} req
* @param {express.Response} res
* @param {Function} next
*/
* Returns a single comment
*/
private async getComment( req: mp.IAuthReq, res: express.Response, next: Function ) {
try {
var comments = this.getModel( "comments" );
Expand Down Expand Up @@ -191,11 +185,8 @@ export default class CommentsController extends Controller {
}

/**
* Attempts to remove a comment by ID
* @param {express.Request} req
* @param {express.Response} res
* @param {Function} next
*/
* Attempts to remove a comment by ID
*/
private async remove( req: mp.IAuthReq, res: express.Response, next: Function ) {
var comments = this.getModel( "comments" );
var findToken: mp.IComment = {
Expand Down Expand Up @@ -230,11 +221,8 @@ export default class CommentsController extends Controller {
}

/**
* Attempts to update a comment by ID
* @param {mp.IAuthReq} req
* @param {express.Response} res
* @param {Function} next
*/
* Attempts to update a comment by ID
*/
private async update( req: mp.IAuthReq, res: express.Response, next: Function ) {
var token: mp.IComment = req.body;
var comments = this.getModel( "comments" );
Expand Down Expand Up @@ -273,11 +261,8 @@ export default class CommentsController extends Controller {
}

/**
* Attempts to create a new comment.
* @param {IAuthReq} req
* @param {express.Response} res
* @param {Function} next
*/
* Attempts to create a new comment
*/
private async create( req: mp.IAuthReq, res: express.Response, next: Function ) {
var token: mp.IComment = req.body;
var comments = this.getModel( "comments" );
Expand Down
12 changes: 5 additions & 7 deletions src/controllers/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ export class Controller {
}

/**
* Called to initialize this controller and its related database objects
* @param {mongodb.Db} db The mongo database to use
* @returns {Promise<Controller>}
*/
* Called to initialize this controller and its related database objects
* @param db The mongo database to use
*/
async initialize( db: mongodb.Db ): Promise<Controller> {
if ( !this._models )
return this;
Expand All @@ -50,9 +49,8 @@ export class Controller {
}

/**
* Gets a model by its collection name
* returns {models.Model}
*/
* Gets a model by its collection name
*/
getModel( collectionName: string ): Model {
var models = Controller._models;
for ( var i = 0, l = models.length; i < l; i++ )
Expand Down
11 changes: 4 additions & 7 deletions src/controllers/cors-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ import { okJson, errJson } from "../serializers";
import express = require( "express" );

/**
* Checks all incomming requests to see if they are CORS approved
*/
* Checks all incomming requests to see if they are CORS approved
*/
export default class CORSController extends Controller {
/**
* Creates an instance of the user manager
* @param {mongodb.Collection} userCollection The mongo collection that stores the users
* @param {mongodb.Collection} sessionCollection The mongo collection that stores the session data
* @param {def.IConfig} The config options of this manager
*/
* Creates an instance of the user manager
*/
constructor( e: express.Express, config: IServer ) {
super( null );

Expand Down
17 changes: 7 additions & 10 deletions src/controllers/emails-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import * as winston from "winston";

export default class EmailsController extends controllerModule.Controller {
/**
* Creates a new instance of the email controller
* @param {IServer} server The server configuration options
* @param {IConfig} config The configuration options
* @param {express.Express} e The express instance of this server
*/
* Creates a new instance of the email controller
* @param server The server configuration options
* @param config The configuration options
* @param e The express instance of this server
*/
constructor( server: IServer, config: IConfig, e: express.Express ) {
super( null );

Expand All @@ -29,11 +29,8 @@ export default class EmailsController extends controllerModule.Controller {
}

/**
* Called whenever a post request is caught by this controller
* @param {express.Request} req The request object
* @param {express.Response} res The response object
* @param {Function} next
*/
* Called whenever a post request is caught by this controller
*/
protected onPost( req: express.Request, res: express.Response, next: Function ): any {
// Set the content type
res.setHeader( 'Content-Type', 'application/json' );
Expand Down
82 changes: 29 additions & 53 deletions src/controllers/page-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import * as jsdom from "jsdom";
import { okJson, errJson } from "../serializers";

/**
* Sets up a prerender server and saves the rendered html requests to mongodb.
* These saved HTML documents can then be sent to web crawlers who cannot interpret javascript.
*/
* Sets up a prerender server and saves the rendered html requests to mongodb.
* These saved HTML documents can then be sent to web crawlers who cannot interpret javascript.
*/
export default class PageRenderer extends Controller {
private renderQueryFlag: string;
private expiration: number;
Expand Down Expand Up @@ -86,11 +86,11 @@ export default class PageRenderer extends Controller {
];

/**
* Creates a new instance of the email controller
* @param {IServer} server The server configuration options
* @param {IConfig} config The configuration options
* @param {express.Express} e The express instance of this server
*/
* Creates a new instance of the email controller
* @param server The server configuration options
* @param config The configuration options
* @param e The express instance of this server
*/
constructor( server: IServer, config: IConfig, e: express.Express ) {
super( [ Model.registerModel( RendersModel ) ] );

Expand All @@ -116,9 +116,8 @@ export default class PageRenderer extends Controller {
}

/**
* Strips the html page of any script tags
* @param {string} html
*/
* Strips the html page of any script tags
*/
private stripScripts( html: string ): string {
var matches = html.match( /<script(?:.*?)>(?:[\S\s]*?)<\/script>/gi );
for ( var i = 0; matches && i < matches.length; i++ )
Expand All @@ -129,9 +128,8 @@ export default class PageRenderer extends Controller {
}

/**
* Gets the URL of a request
* @param {express.Request} req
*/
* Gets the URL of a request
*/
getUrl( req: express.Request ): string {
var protocol = req.protocol;
if ( req.get( 'CF-Visitor' ) ) {
Expand All @@ -150,10 +148,8 @@ export default class PageRenderer extends Controller {
}

/**
* Fetches a page and strips it of all its script tags
* @param {string} url
* @param {Promise<string>}
*/
* Fetches a page and strips it of all its script tags
*/
private renderPage( url: string ): Promise<string> {
var that = this;

Expand Down Expand Up @@ -207,11 +203,8 @@ export default class PageRenderer extends Controller {
}

/**
* Determines if the request comes from a bot. If so, a prerendered page is sent back which excludes any script tags
* @param req
* @param response
* @param next
*/
* Determines if the request comes from a bot. If so, a prerendered page is sent back which excludes any script tags
*/
async processBotRequest( req: express.Request, res: express.Response, next: Function ) {
if ( req.query.__render__request )
return next();
Expand Down Expand Up @@ -263,10 +256,8 @@ export default class PageRenderer extends Controller {
};

/**
* Determines if the request comes from a bot
* @param {express.Request} req
* @returns {boolean}
*/
* Determines if the request comes from a bot
*/
private shouldShowPrerenderedPage( req: express.Request ): boolean {
var userAgent = req.headers[ 'user-agent' ]
, bufferAgent = req.headers[ 'x-bufferbot' ]
Expand All @@ -292,11 +283,8 @@ export default class PageRenderer extends Controller {
}

/**
* Attempts to find a render by ID and then display it back to the user
* @param {express.Request} req
* @param {express.Response} res
* @param {Function} next
*/
* Attempts to find a render by ID and then display it back to the user
*/
private async previewRender( req: express.Request, res: express.Response, next: Function ) {
res.setHeader( 'Content-Type', 'text/html' );
var renders = this.getModel( "renders" );
Expand All @@ -323,11 +311,8 @@ export default class PageRenderer extends Controller {
}

/**
* Attempts to remove a render by ID
* @param {express.Request} req
* @param {express.Response} res
* @param {Function} next
*/
* Attempts to remove a render by ID
*/
private async removeRender( req: express.Request, res: express.Response, next: Function ) {
var renders = this.getModel( "renders" );

Expand All @@ -348,12 +333,9 @@ export default class PageRenderer extends Controller {
}

/**
* This funciton checks the logged in user is an admin. If not an admin it returns an error,
* if true it passes the scope onto the next function in the queue
* @param {express.Request} req
* @param {express.Response} res
* @param {Function} next
*/
* This funciton checks the logged in user is an admin. If not an admin it returns an error,
* if true it passes the scope onto the next function in the queue
*/
private async authenticateAdmin( req: express.Request, res: express.Response, next: Function ) {
var users = UsersService.getSingleton();

Expand All @@ -380,11 +362,8 @@ export default class PageRenderer extends Controller {
}

/**
* Returns an array of IPost items
* @param {express.Request} req
* @param {express.Response} res
* @param {Function} next
*/
* Returns an array of IPost items
*/
private async getRenders( req: express.Request, res: express.Response, next: Function ) {
var renders = this.getModel( "renders" );
var that = this;
Expand Down Expand Up @@ -435,11 +414,8 @@ export default class PageRenderer extends Controller {
}

/**
* Removes all cache items from the db
* @param {express.Request} req
* @param {express.Response} res
* @param {Function} next
*/
* Removes all cache items from the db
*/
private async clearRenders( req: express.Request, res: express.Response, next: Function ) {
var renders = this.getModel( "renders" );

Expand Down
Loading

0 comments on commit 5611734

Please sign in to comment.