Upload refactor #242

Merged
bones7242 merged 24 commits from upload-refactor into master 2017-11-13 21:39:21 +01:00
15 changed files with 53 additions and 99 deletions
Showing only changes of commit 40d40c2278 - Show all commits

3
.gitignore vendored
View file

@ -1,3 +1,4 @@
node_modules node_modules
.idea .idea
config/config.json config/config.json
config/speechConfig.js

View file

@ -1,15 +0,0 @@
{
"WalletConfig": {
"LbryClaimAddress": "LBRY_CLAIM_ADDRESS"
},
"Database": {
"Username": "MYSQL_USERNAME",
"Password": "MYSQL_PASSWORD"
},
"Logging": {
"SlackWebHook": "SLACK_WEB_HOOK"
},
"Session": {
"SessionKey": "SESSION_KEY"
}
}

View file

@ -1 +0,0 @@
{}

View file

@ -1,23 +0,0 @@
{
"WalletConfig": {
"LbryClaimAddress": null,
"DefaultChannel": null
},
"AnalyticsConfig":{
"GoogleId": null
},
"Database": {
"Database": "lbry",
"Username": null,
"Password": null
},
"Logging": {
"LogLevel": null,
"SlackWebHook": null,
"SlackErrorChannel": null,
"SlackInfoChannel": null
},
"Session": {
"SessionKey": null
}
}

View file

@ -1,13 +0,0 @@
{
"WalletConfig": {
"DefaultChannel": "@speechDev"
},
"AnalyticsConfig":{
"GoogleId": "UA-100747990-1"
},
"Logging": {
"LogLevel": "silly",
"SlackErrorChannel": "#staging_speech-errors",
"SlackInfoChannel": "none"
}
}

View file

@ -1,13 +0,0 @@
{
"WalletConfig": {
"DefaultChannel": "@speech"
},
"AnalyticsConfig":{
"GoogleId": "UA-60403362-3"
},
"Logging": {
"LogLevel": "verbose",
"SlackErrorChannel": "#speech-errors",
"SlackInfoChannel": "#speech-logs"
}
}

View file

@ -1,29 +1,26 @@
const config = require('config'); const config = require('./speechConfig.js');
const SLACK_WEB_HOOK = config.get('Logging.SlackWebHook');
const SLACK_ERROR_CHANNEL = config.get('Logging.SlackErrorChannel');
const SLACK_INFO_CHANNEL = config.get('Logging.SlackInfoChannel');
const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook; const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook;
module.exports = (winston) => { module.exports = (winston) => {
if (SLACK_WEB_HOOK) { if (config.logging.slackWebHook) {
// add a transport for errors to slack // add a transport for errors to slack
winston.add(winstonSlackWebHook, { winston.add(winstonSlackWebHook, {
name : 'slack-errors-transport', name : 'slack-errors-transport',
level : 'error', level : 'error',
webhookUrl: SLACK_WEB_HOOK, webhookUrl: config.logging.slackWebHook,
channel : SLACK_ERROR_CHANNEL, channel : config.logging.slackErrorChannel,
username : 'spee.ch', username : 'spee.ch',
iconEmoji : ':face_with_head_bandage:', iconEmoji : ':face_with_head_bandage:',
}); });
winston.add(winstonSlackWebHook, { winston.add(winstonSlackWebHook, {
name : 'slack-info-transport', name : 'slack-info-transport',
level : 'info', level : 'info',
webhookUrl: SLACK_WEB_HOOK, webhookUrl: config.logging.slackWebHook,
channel : SLACK_INFO_CHANNEL, channel : config.logging.slackInfoChannel,
username : 'spee.ch', username : 'spee.ch',
iconEmoji : ':nerd_face:', iconEmoji : ':nerd_face:',
}); });
// send test message // send test message
winston.error('Slack error logging is online.'); winston.error('Slack error logging is online.');
winston.info('Slack info logging is online.'); winston.info('Slack info logging is online.');
} else { } else {

View file

@ -0,0 +1,23 @@
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
module.exports = {
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
wallet: {
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
lbryClaimAddress: null,
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
defaultChannel : null,
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
},
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
analytics: {
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
googleId: null,
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
},
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
sql: {
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
database: 'lbry',
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
username: null,
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
password: null,
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
},
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
logging: {
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
logLevel : null,
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
slackWebHook : null,
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
slackErrorChannel: null,
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
slackInfoChannel : null,
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
},
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
session: {
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
sessionKey: null,
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
},
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`
};
kauffj commented 2017-11-10 18:24:47 +01:00 (Migrated from github.com)
Review

A more common convention for this is probably speechConfig.example.js or speechConfig.js.example.

A more common convention for this is probably `speechConfig.example.js` or `speechConfig.js.example`.
bones7242 commented 2017-11-13 20:25:03 +01:00 (Migrated from github.com)
Review

I like speechConfig.js.example

I like `speechConfig.js.example`

View file

@ -1,8 +1,8 @@
const logger = require('winston'); const logger = require('winston');
const ua = require('universal-analytics'); const ua = require('universal-analytics');
const config = require('config'); const config = require('../config/speechConfig.js');
const db = require('../models'); const db = require('../models');
const googleApiKey = config.get('AnalyticsConfig.GoogleId'); const googleApiKey = config.analytics.googleId;
module.exports = { module.exports = {
postToStats (action, url, ipAddress, name, claimId, result) { postToStats (action, url, ipAddress, name, claimId, result) {

View file

@ -1,15 +1,13 @@
const config = require('config'); const config = require('../config/speechConfig.js');
const logger = require('winston'); const logger = require('winston');
const fs = require('fs');
module.exports = function () { module.exports = function () {
// get the config file // get the config file
const defaultConfigFile = JSON.parse(fs.readFileSync('./config/default.json'));
for (let configCategoryKey in defaultConfigFile) { for (let configCategoryKey in config) {
if (defaultConfigFile.hasOwnProperty(configCategoryKey)) { if (config.hasOwnProperty(configCategoryKey)) {
// get the final variables for each config category // get the final variables for each config category
const configVariables = config.get(configCategoryKey); const configVariables = config[configCategoryKey];
for (let configVarKey in configVariables) { for (let configVarKey in configVariables) {
if (configVariables.hasOwnProperty(configVarKey)) { if (configVariables.hasOwnProperty(configVarKey)) {
// print each variable // print each variable

View file

@ -1,10 +1,10 @@
const Handlebars = require('handlebars'); const Handlebars = require('handlebars');
const config = require('config'); const config = require('../config/speechConfig.js');
module.exports = { module.exports = {
// define any extra helpers you may need // define any extra helpers you may need
googleAnalytics () { googleAnalytics () {
const googleApiKey = config.get('AnalyticsConfig.GoogleId'); const googleApiKey = config.analytics.googleId;
return new Handlebars.SafeString( return new Handlebars.SafeString(
`<script> `<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View file

@ -1,7 +1,7 @@
const logger = require('winston'); const logger = require('winston');
const fs = require('fs'); const fs = require('fs');
const db = require('../models'); const db = require('../models');
const config = require('config'); const config = require('../config/speechConfig.js');
module.exports = { module.exports = {
validateApiPublishRequest (body, files) { validateApiPublishRequest (body, files) {
@ -110,7 +110,7 @@ module.exports = {
license, license,
nsfw, nsfw,
}, },
claim_address: config.get('WalletConfig.LbryClaimAddress'), claim_address: config.wallet.lbryClaimAddress,
}; };
// add thumbnail to channel if video // add thumbnail to channel if video
if (thumbnail !== null) { if (thumbnail !== null) {
@ -137,7 +137,7 @@ module.exports = {
db.File.findAll({ where: { name } }) db.File.findAll({ where: { name } })
.then(result => { .then(result => {
if (result.length >= 1) { if (result.length >= 1) {
const claimAddress = config.get('WalletConfig.LbryClaimAddress'); const claimAddress = config.wallet.lbryClaimAddress;
// filter out any results that were not published from spee.ch's wallet address // filter out any results that were not published from spee.ch's wallet address
const filteredResult = result.filter((claim) => { const filteredResult = result.filter((claim) => {
return (claim.address === claimAddress); return (claim.address === claimAddress);

View file

@ -2,13 +2,13 @@ const fs = require('fs');
const path = require('path'); const path = require('path');
const Sequelize = require('sequelize'); const Sequelize = require('sequelize');
const basename = path.basename(module.filename); const basename = path.basename(module.filename);
const config = require('config'); const config = require('../config/speechConfig.js');
const db = {}; const db = {};
const logger = require('winston'); const logger = require('winston');
const database = config.get('Database.Database'); const database = config.sql.database;
const username = config.get('Database.Username'); const username = config.sql.username;
const password = config.get('Database.Password'); const password = config.sql.password;
const sequelize = new Sequelize(database, username, password, { const sequelize = new Sequelize(database, username, password, {
host : 'localhost', host : 'localhost',

View file

@ -175,7 +175,7 @@ var publishFileFunctions = {
kauffj commented 2017-11-10 18:33:00 +01:00 (Migrated from github.com)
Review

Presumably const

Presumably `const`
kauffj commented 2017-11-10 18:33:35 +01:00 (Migrated from github.com)
Review

Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.

Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
kauffj commented 2017-11-10 18:33:00 +01:00 (Migrated from github.com)
Review

Presumably const

Presumably `const`
kauffj commented 2017-11-10 18:33:35 +01:00 (Migrated from github.com)
Review

Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.

Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
}, },
showUploadProgressMessage: function (percentage){ showUploadProgressMessage: function (percentage){
this.updatePublishStatus('<p>File is loading to server</p>'); this.updatePublishStatus('<p>File is loading to server</p>');
this.updateUploadPercent('<p class="blue">' + percentage + '</p>'); this.updateUploadPercent('<p class="blue">' + percentage + '% </p>');
kauffj commented 2017-11-10 18:33:00 +01:00 (Migrated from github.com)
Review

Presumably const

Presumably `const`
kauffj commented 2017-11-10 18:33:35 +01:00 (Migrated from github.com)
Review

Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.

Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
kauffj commented 2017-11-10 18:33:00 +01:00 (Migrated from github.com)
Review

Presumably const

Presumably `const`
kauffj commented 2017-11-10 18:33:35 +01:00 (Migrated from github.com)
Review

Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.

Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
}, },
showFilePublishUpdate: function (msg) { showFilePublishUpdate: function (msg) {
this.updatePublishStatus('<p>' + msg + '</p>'); this.updatePublishStatus('<p>' + msg + '</p>');

kauffj commented 2017-11-10 18:33:00 +01:00 (Migrated from github.com)
Review

Presumably const

Presumably `const`
kauffj commented 2017-11-10 18:33:35 +01:00 (Migrated from github.com)
Review

Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.

Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
kauffj commented 2017-11-10 18:33:00 +01:00 (Migrated from github.com)
Review

Presumably const

Presumably `const`
kauffj commented 2017-11-10 18:33:35 +01:00 (Migrated from github.com)
Review

Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.

Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.

View file

@ -6,7 +6,7 @@ const expressHandlebars = require('express-handlebars');
const Handlebars = require('handlebars'); const Handlebars = require('handlebars');
const handlebarsHelpers = require('./helpers/handlebarsHelpers.js'); const handlebarsHelpers = require('./helpers/handlebarsHelpers.js');
const { populateLocalsDotUser, serializeSpeechUser, deserializeSpeechUser } = require('./helpers/authHelpers.js'); const { populateLocalsDotUser, serializeSpeechUser, deserializeSpeechUser } = require('./helpers/authHelpers.js');
const config = require('config'); const config = require('./config/speechConfig.js');
const logger = require('winston'); const logger = require('winston');
const { getDownloadDirectory } = require('./helpers/lbryApi'); const { getDownloadDirectory } = require('./helpers/lbryApi');
const helmet = require('helmet'); const helmet = require('helmet');
@ -17,9 +17,9 @@ const passport = require('passport');
const cookieSession = require('cookie-session'); const cookieSession = require('cookie-session');
// configure logging // configure logging
const logLevel = config.get('Logging.LogLevel'); const logLevel = config.logging.logLevel;
require('./config/loggerConfig.js')(logger, logLevel); require('./config/loggerConfig.js')(logger, logLevel);
require('./config/slackLoggerConfig.js')(logger); require('./config/slackConfig.js')(logger);
// check for global config variables // check for global config variables
require('./helpers/configVarCheck.js')(); require('./helpers/configVarCheck.js')();
@ -42,7 +42,7 @@ app.use((req, res, next) => { // custom logging middleware to log all incoming
// initialize passport // initialize passport
app.use(cookieSession({ app.use(cookieSession({
name : 'session', name : 'session',
keys : [config.get('Session.SessionKey')], keys : [config.session.sessionKey],
maxAge: 24 * 60 * 60 * 1000, // 24 hours maxAge: 24 * 60 * 60 * 1000, // 24 hours
})); }));
app.use(passport.initialize()); app.use(passport.initialize());