moved remaining helpers except for publishHelpers

This commit is contained in:
bill bittner 2018-04-26 19:19:11 -07:00
parent cfb7e47fbd
commit b785edf100
21 changed files with 40 additions and 95 deletions

View file

@ -55,7 +55,7 @@ function Server () {
app.use(requestLogger);
// configure passport
const speechPassport = require('./server/speechPassport/index');
const speechPassport = require('./server/speechPassport');
// initialize passport
const sessionKey = siteConfig.auth.sessionKey;
app.use(cookieSession({

View file

@ -1,6 +1,6 @@
const logger = require('winston');
const db = require('../models');
const lbryApi = require('../helpers/lbryApi.js');
const lbryApi = require('../utils/lbryApi.js');
const publishHelpers = require('../helpers/publishHelpers.js');
const { publishing: { primaryClaimAddress, additionalClaimAddresses } } = require('../../config/siteConfig.js');
const Sequelize = require('sequelize');

View file

@ -1,17 +0,0 @@
const logger = require('winston');
module.exports = (config) => {
// get the config file
for (let configCategoryKey in config) {
if (config.hasOwnProperty(configCategoryKey)) {
// get the final variables for each config category
const configVariables = config[configCategoryKey];
for (let configVarKey in configVariables) {
if (configVariables.hasOwnProperty(configVarKey)) {
// print each variable
logger.debug(`CONFIG CHECK: ${configCategoryKey}.${configVarKey} === ${configVariables[configVarKey]}`);
}
}
}
}
};

View file

@ -1,25 +0,0 @@
module.exports = {
returnShortId: function (claimsArray, longId) {
let claimIndex;
let shortId = longId.substring(0, 1); // default short id is the first letter
let shortIdLength = 0;
// find the index of this claim id
claimIndex = claimsArray.findIndex(element => {
return element.claimId === longId;
});
if (claimIndex < 0) {
throw new Error('claim id not found in claims list');
}
// get an array of all claims with lower height
let possibleMatches = claimsArray.slice(0, claimIndex);
// remove certificates with the same prefixes until none are left.
while (possibleMatches.length > 0) {
shortIdLength += 1;
shortId = longId.substring(0, shortIdLength);
possibleMatches = possibleMatches.filter(element => {
return (element.claimId && (element.claimId.substring(0, shortIdLength) === shortId));
});
}
return shortId;
},
};

View file

@ -1,38 +0,0 @@
const logger = require('winston');
const db = require('../models');
module.exports = {
postToStats (action, url, ipAddress, name, claimId, result) {
logger.debug('action:', action);
// make sure the result is a string
if (result && (typeof result !== 'string')) {
result = result.toString();
}
// make sure the ip address(es) are a string
if (ipAddress && (typeof ipAddress !== 'string')) {
ipAddress = ipAddress.toString();
}
db.File
.findOne({where: { name, claimId }})
.then(file => {
// create record in the db
let FileId;
if (file) {
FileId = file.dataValues.id;
} else {
FileId = null;
}
return db.Request
.create({
action,
url,
ipAddress,
result,
FileId,
});
})
.catch(error => {
logger.error('Sequelize error >>', error);
});
},
};

View file

@ -1,5 +1,5 @@
const logger = require('winston');
const { returnShortId } = require('../helpers/sequelizeHelpers.js');
const returnShortId = require('./utils/returnShortId.js');
module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
const Certificate = sequelize.define(

View file

@ -1,5 +1,5 @@
const logger = require('winston');
const { returnShortId } = require('../helpers/sequelizeHelpers.js');
const returnShortId = require('./utils/returnShortId.js');
const { assetDefaults: { thumbnail: defaultThumbnail }, details: { host } } = require('../../config/siteConfig.js');
function determineFileExtensionFromContentType (contentType) {

View file

@ -0,0 +1,25 @@
const returnShortId = (claimsArray, longId) => {
let claimIndex;
let shortId = longId.substring(0, 1); // default short id is the first letter
let shortIdLength = 0;
// find the index of this claim id
claimIndex = claimsArray.findIndex(element => {
return element.claimId === longId;
});
if (claimIndex < 0) {
throw new Error('claim id not found in claims list');
}
// get an array of all claims with lower height
let possibleMatches = claimsArray.slice(0, claimIndex);
// remove certificates with the same prefixes until none are left.
while (possibleMatches.length > 0) {
shortIdLength += 1;
shortId = longId.substring(0, shortIdLength);
possibleMatches = possibleMatches.filter(element => {
return (element.claimId && (element.claimId.substring(0, shortIdLength) === shortId));
});
}
return shortId;
};
module.exports = returnShortId;

View file

@ -1,5 +1,5 @@
const { checkChannelAvailability } = require('../../controllers/publishController.js');
const { sendGATimingEvent } = require('../../helpers/googleAnalytics.js');
const { sendGATimingEvent } = require('../../utils/googleAnalytics.js');
const { handleErrorResponse } = require('../utils/errorHandlers.js');
/*

View file

@ -1,5 +1,5 @@
const { claimNameIsAvailable } = require('../../controllers/publishController.js');
const { sendGATimingEvent } = require('../../helpers/googleAnalytics.js');
const { sendGATimingEvent } = require('../../utils/googleAnalytics.js');
const { handleErrorResponse } = require('../utils/errorHandlers.js');
/*

View file

@ -1,4 +1,4 @@
const { getClaim } = require('../../helpers/lbryApi.js');
const { getClaim } = require('../../utils/lbryApi.js');
const { addGetResultsToFileData, createFileData } = require('../../helpers/publishHelpers.js');
const { handleErrorResponse } = require('../utils/errorHandlers.js');
const db = require('../../models');

View file

@ -1,4 +1,4 @@
const { getClaimList } = require('../../helpers/lbryApi.js');
const { getClaimList } = require('../../utils/lbryApi.js');
const { handleErrorResponse } = require('../utils/errorHandlers.js');
/*

View file

@ -1,7 +1,7 @@
const { createBasicPublishParams, createThumbnailPublishParams, parsePublishApiRequestBody, parsePublishApiRequestFiles } = require('../../helpers/publishHelpers.js');
const { claimNameIsAvailable, publish } = require('../../controllers/publishController.js');
const { authenticateUser } = require('../../auth/authentication.js');
const { sendGATimingEvent } = require('../../helpers/googleAnalytics.js');
const { sendGATimingEvent } = require('../../utils/googleAnalytics.js');
const { handleErrorResponse } = require('../utils/errorHandlers.js');
const { details: { host } } = require('../../../config/siteConfig.js');

View file

@ -1,4 +1,4 @@
const { resolveUri } = require('../../helpers/lbryApi.js');
const { resolveUri } = require('../../utils/lbryApi.js');
const { handleErrorResponse } = require('../utils/errorHandlers.js');
/*

View file

@ -12,7 +12,7 @@ const claimShortId = require('./claimShortId');
const claimList = require('./claimList');
const fileAvailability = require('./fileAvailability');
const multipartMiddleware = require('../../helpers/multipartMiddleware');
const multipartMiddleware = require('../utils/multipartMiddleware');
module.exports = (app) => {
// channel routes

View file

@ -1,4 +1,4 @@
const { sendGAServeEvent } = require('../../helpers/googleAnalytics');
const { sendGAServeEvent } = require('../../utils/googleAnalytics');
const {
determineResponseType,
logRequestData,

View file

@ -1,4 +1,4 @@
const { sendGAServeEvent } = require('../../helpers/googleAnalytics');
const { sendGAServeEvent } = require('../../utils/googleAnalytics');
const {
determineResponseType,
flipClaimNameAndIdForBackwardsCompatibility,

View file

@ -1,5 +1,5 @@
const multipart = require('connect-multiparty');
const { publishing: { uploadDirectory } } = require('../../config/siteConfig.js');
const { publishing: { uploadDirectory } } = require('../../../config/siteConfig.js');
const multipartMiddleware = multipart({uploadDir: uploadDirectory});
module.exports = multipartMiddleware;

View file

@ -1,5 +1,5 @@
const PassportLocalStrategy = require('passport-local').Strategy;
const lbryApi = require('../../helpers/lbryApi.js');
const lbryApi = require('../../utils/lbryApi.js');
const logger = require('winston');
const db = require('../../models/index');