Skip to content

Commit

Permalink
Moved utils constants to lib/constants
Browse files Browse the repository at this point in the history
  • Loading branch information
kirrg001 committed Dec 14, 2017
1 parent c5169e2 commit a3091a3
Show file tree
Hide file tree
Showing 32 changed files with 118 additions and 111 deletions.
4 changes: 2 additions & 2 deletions core/server/adapters/storage/LocalFileStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var serveStatic = require('express').static,
moment = require('moment'),
config = require('../../config'),
common = require('../../lib/common'),
globalUtils = require('../../utils'),
constants = require('../../lib/constants'),
urlService = require('../../services/url'),
StorageBase = require('ghost-storage-base');

Expand Down Expand Up @@ -85,7 +85,7 @@ class LocalFileStore extends StorageBase {
return serveStatic(
self.storagePath,
{
maxAge: globalUtils.ONE_YEAR_MS,
maxAge: constants.ONE_YEAR_MS,
fallthrough: false,
onEnd: function onEnd() {
common.logging.info('LocalFileStorage.serve', req.path, moment().diff(startedAtMoment, 'ms') + 'ms');
Expand Down
10 changes: 5 additions & 5 deletions core/server/api/authentication.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
var Promise = require('bluebird'),
_ = require('lodash'),
validator = require('validator'),
config = require('../config'),
common = require('../lib/common'),
security = require('../lib/security'),
constants = require('../lib/constants'),
pipeline = require('../lib/promise/pipeline'),
mail = require('../services/mail'),
globalUtils = require('../utils'),
urlService = require('../services/url'),
localUtils = require('./utils'),
models = require('../models'),
config = require('../config'),
common = require('../lib/common'),
security = require('../lib/security'),
spamPrevention = require('../web/middleware/api/spam-prevention'),
mailAPI = require('./mail'),
settingsAPI = require('./settings'),
Expand Down Expand Up @@ -169,7 +169,7 @@ authentication = {
}

token = security.tokens.resetToken.generateHash({
expires: Date.now() + globalUtils.ONE_DAY_MS,
expires: Date.now() + constants.ONE_DAY_MS,
email: email,
dbHash: dbHash,
password: user.get('password')
Expand Down
2 changes: 1 addition & 1 deletion core/server/api/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function getBaseConfig() {
*
* We need to load the client credentials dynamically.
*
* **See:** [API Methods](index.js.html#api%20methods)
* **See:** [API Methods](constants.js.html#api%20methods)
*/
configuration = {

Expand Down
2 changes: 1 addition & 1 deletion core/server/api/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var Promise = require('bluebird'),
/**
* ## DB API Methods
*
* **See:** [API Methods](index.js.html#api%20methods)
* **See:** [API Methods](constants.js.html#api%20methods)
*/
db = {
/**
Expand Down
2 changes: 1 addition & 1 deletion core/server/api/mail.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function sendMail(object) {
/**
* ## Mail API Methods
*
* **See:** [API Methods](index.js.html#api%20methods)
* **See:** [API Methods](constants.js.html#api%20methods)
* @typedef Mail
* @param mail
*/
Expand Down
2 changes: 1 addition & 1 deletion core/server/api/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var Promise = require('bluebird'),
/**
* ## Notification API Methods
*
* **See:** [API Methods](index.js.html#api%20methods)
* **See:** [API Methods](constants.js.html#api%20methods)
*/
notifications = {

Expand Down
2 changes: 1 addition & 1 deletion core/server/api/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var Promise = require('bluebird'),
/**
* ### Posts API Methods
*
* **See:** [API Methods](index.js.html#api%20methods)
* **See:** [API Methods](constants.js.html#api%20methods)
*/

posts = {
Expand Down
2 changes: 1 addition & 1 deletion core/server/api/roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var Promise = require('bluebird'),
/**
* ## Roles API Methods
*
* **See:** [API Methods](index.js.html#api%20methods)
* **See:** [API Methods](constants.js.html#api%20methods)
*/
roles = {
/**
Expand Down
2 changes: 1 addition & 1 deletion core/server/api/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ canEditAllSettings = function (settingsInfo, options) {
/**
* ## Settings API Methods
*
* **See:** [API Methods](index.js.html#api%20methods)
* **See:** [API Methods](constants.js.html#api%20methods)
*/
settings = {

Expand Down
2 changes: 1 addition & 1 deletion core/server/api/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var Promise = require('bluebird'),
/**
* ## Slack API Method
*
* **See:** [API Methods](index.js.html#api%20methods)
* **See:** [API Methods](constants.js.html#api%20methods)
* @typedef Slack
* @param slack
*/
Expand Down
2 changes: 1 addition & 1 deletion core/server/api/slugs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var Promise = require('bluebird'),
/**
* ## Slugs API Methods
*
* **See:** [API Methods](index.js.html#api%20methods)
* **See:** [API Methods](constants.js.html#api%20methods)
*/
slugs = {

Expand Down
2 changes: 1 addition & 1 deletion core/server/api/subscribers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var Promise = require('bluebird'),
/**
* ### Subscribers API Methods
*
* **See:** [API Methods](index.js.html#api%20methods)
* **See:** [API Methods](constants.js.html#api%20methods)
*/
subscribers = {
/**
Expand Down
2 changes: 1 addition & 1 deletion core/server/api/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var Promise = require('bluebird'),
/**
* ### Tags API Methods
*
* **See:** [API Methods](index.js.html#api%20methods)
* **See:** [API Methods](constants.js.html#api%20methods)
*/
tags = {
/**
Expand Down
2 changes: 1 addition & 1 deletion core/server/api/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var debug = require('ghost-ignition').debug('api:themes'),
/**
* ## Themes API Methods
*
* **See:** [API Methods](index.js.html#api%20methods)
* **See:** [API Methods](constants.js.html#api%20methods)
*/
themes = {
/**
Expand Down
2 changes: 1 addition & 1 deletion core/server/api/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var Promise = require('bluebird'),
/**
* ## Upload API Methods
*
* **See:** [API Methods](index.js.html#api%20methods)
* **See:** [API Methods](constants.js.html#api%20methods)
*/
upload = {

Expand Down
2 changes: 1 addition & 1 deletion core/server/api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var Promise = require('bluebird'),
/**
* ### Users API Methods
*
* **See:** [API Methods](index.js.html#api%20methods)
* **See:** [API Methods](constants.js.html#api%20methods)
*/
users = {
/**
Expand Down
2 changes: 1 addition & 1 deletion core/server/api/webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function makeRequests(webhooksCollection, payload, options) {
/**
* ## Webhook API Methods
*
* **See:** [API Methods](index.js.html#api%20methods)
* **See:** [API Methods](constants.js.html#api%20methods)
*/
webhooks = {

Expand Down
4 changes: 2 additions & 2 deletions core/server/apps/private-blogging/lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var fs = require('fs-extra'),
path = require('path'),
config = require('../../../config'),
urlService = require('../../../services/url'),
globalUtils = require('../../../utils'),
constants = require('../../../lib/constants'),
common = require('../../../lib/common'),
settingsCache = require('../../../services/settings/cache'),
privateRoute = '/' + config.get('routeKeywords').private + '/',
Expand Down Expand Up @@ -32,7 +32,7 @@ privateBlogging = {
res.isPrivateBlog = true;

return session({
maxAge: globalUtils.ONE_MONTH_MS,
maxAge: constants.ONE_MONTH_MS,
signed: false
})(req, res, next);
},
Expand Down
14 changes: 14 additions & 0 deletions core/server/lib/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
ONE_HOUR_S: 3600,
ONE_DAY_S: 86400,
ONE_MONTH_S: 2628000,
SIX_MONTH_S: 15768000,
ONE_YEAR_S: 31536000,
FIVE_MINUTES_MS: 300000,
ONE_HOUR_MS: 3600000,
ONE_DAY_MS: 86400000,
ONE_WEEK_MS: 604800000,
ONE_MONTH_MS: 2628000000,
SIX_MONTH_MS: 15768000000,
ONE_YEAR_MS: 31536000000
};
13 changes: 8 additions & 5 deletions core/server/models/invite.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
var ghostBookshelf = require('./base'),
globalUtils = require('../utils'),
crypto = require('crypto'),
'use strict';

const crypto = require('crypto'),
_ = require('lodash'),
Invite,
constants = require('../lib/constants'),
ghostBookshelf = require('./base');

let Invite,
Invites;

Invite = ghostBookshelf.Model.extend({
Expand Down Expand Up @@ -49,7 +52,7 @@ Invite = ghostBookshelf.Model.extend({
options = this.filterOptions(options, 'add');
options.withRelated = _.union(options.withRelated, options.include);

data.expires = Date.now() + globalUtils.ONE_WEEK_MS;
data.expires = Date.now() + constants.ONE_WEEK_MS;
data.status = 'pending';

// @TODO: call a util fn?
Expand Down
10 changes: 5 additions & 5 deletions core/server/services/auth/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var Promise = require('bluebird'),
debug = require('ghost-ignition').debug('auth:utils'),
models = require('../../models'),
security = require('../../lib/security'),
globalUtils = require('../../utils'),
constants = require('../../lib/constants'),
knex = require('../../data/db').knex,
_private = {};

Expand All @@ -27,7 +27,7 @@ _private.decreaseOldAccessTokenExpiry = function decreaseOldAccessTokenExpiry(da
}

return models.Accesstoken.edit({
expires: Date.now() + globalUtils.FIVE_MINUTES_MS
expires: Date.now() + constants.FIVE_MINUTES_MS
}, _.merge({id: oldAccessToken.id}, options));
});
};
Expand Down Expand Up @@ -56,8 +56,8 @@ _private.handleTokenCreation = function handleTokenCreation(data, options) {
oldRefreshId = data.oldRefreshId,
newAccessToken = security.identifier.uid(191),
newRefreshToken = security.identifier.uid(191),
accessExpires = Date.now() + globalUtils.ONE_MONTH_MS,
refreshExpires = Date.now() + globalUtils.SIX_MONTH_MS,
accessExpires = Date.now() + constants.ONE_MONTH_MS,
refreshExpires = Date.now() + constants.SIX_MONTH_MS,
clientId = data.clientId,
userId = data.userId;

Expand Down Expand Up @@ -85,7 +85,7 @@ _private.handleTokenCreation = function handleTokenCreation(data, options) {
return {
access_token: newAccessToken,
refresh_token: newRefreshToken,
expires_in: globalUtils.ONE_MONTH_S
expires_in: constants.ONE_MONTH_S
};
});
};
Expand Down
4 changes: 2 additions & 2 deletions core/server/services/themes/Storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var fs = require('fs-extra'),
Promise = require('bluebird'),
config = require('../../config'),
security = require('../../lib/security'),
globalUtils = require('../../utils'),
zipFolder = require('../../utils/zip-folder'),
LocalFileStorage = require('../../adapters/storage/LocalFileStorage');

/**
Expand Down Expand Up @@ -37,7 +37,7 @@ class ThemeStorage extends LocalFileStorage {

fs.ensureDir(zipBasePath)
.then(function () {
return Promise.promisify(globalUtils.zipFolder)(themePath, zipPath);
return Promise.promisify(zipFolder)(themePath, zipPath);
})
.then(function (length) {
res.set({
Expand Down
29 changes: 2 additions & 27 deletions core/server/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,2 @@
var utils;

utils = {
/**
* Timespans in seconds and milliseconds for better readability
*/
/* eslint-disable key-spacing */
ONE_HOUR_S: 3600,
ONE_DAY_S: 86400,
ONE_MONTH_S: 2628000,
SIX_MONTH_S: 15768000,
ONE_YEAR_S: 31536000,
FIVE_MINUTES_MS: 300000,
ONE_HOUR_MS: 3600000,
ONE_DAY_MS: 86400000,
ONE_WEEK_MS: 604800000,
ONE_MONTH_MS: 2628000000,
SIX_MONTH_MS: 15768000000,
ONE_YEAR_MS: 31536000000,
// eslint-enable key-spacing */

readCSV: require('./read-csv'),
zipFolder: require('./zip-folder'),
ghostVersion: require('./ghost-version')
};

module.exports = utils;
// here for mocking, will be moved soon
module.exports.readCSV = require('./read-csv');
4 changes: 2 additions & 2 deletions core/server/web/admin/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var debug = require('ghost-ignition').debug('admin'),

// App requires
config = require('../../config'),
globalUtils = require('../../utils'),
constants = require('../../lib/constants'),
urlService = require('../../services/url'),

// Middleware
Expand Down Expand Up @@ -35,7 +35,7 @@ module.exports = function setupAdminApp() {
configMaxAge = config.get('caching:admin:maxAge');
adminApp.use('/assets', serveStatic(
config.get('paths').clientAssets,
{maxAge: (configMaxAge || configMaxAge === 0) ? configMaxAge : globalUtils.ONE_YEAR_MS, fallthrough: false}
{maxAge: (configMaxAge || configMaxAge === 0) ? configMaxAge : constants.ONE_YEAR_MS, fallthrough: false}
));

// Service Worker for offline support
Expand Down
12 changes: 6 additions & 6 deletions core/server/web/middleware/static-theme.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var _ = require('lodash'),
var _ = require('lodash'),
express = require('express'),
path = require('path'),
config = require('../../config'),
themeUtils = require('../../services/themes'),
utils = require('../../utils');
path = require('path'),
config = require('../../config'),
constants = require('../../lib/constants'),
themeUtils = require('../../services/themes');

function isBlackListedFileType(file) {
var blackListedFileTypes = ['.hbs', '.md', '.json'],
Expand All @@ -25,7 +25,7 @@ function forwardToExpressStatic(req, res, next) {
var configMaxAge = config.get('caching:theme:maxAge');

express.static(themeUtils.getActive().path,
{maxAge: (configMaxAge || configMaxAge === 0) ? configMaxAge : utils.ONE_YEAR_MS}
{maxAge: (configMaxAge || configMaxAge === 0) ? configMaxAge : constants.ONE_YEAR_MS}
)(req, res, next);
}

Expand Down
Loading

0 comments on commit a3091a3

Please sign in to comment.