From 63458aff19a1c7a0c970a8406ddd7397b733a210 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 6 Nov 2017 14:15:47 -0800 Subject: [PATCH 1/5] changed the multipart download directory --- controllers/publishController.js | 15 ++++++++++----- models/index.js | 2 +- package.json | 1 - routes/api-routes.js | 5 +++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/controllers/publishController.js b/controllers/publishController.js index 19766c05..5dd06482 100644 --- a/controllers/publishController.js +++ b/controllers/publishController.js @@ -6,13 +6,13 @@ const publishHelpers = require('../helpers/publishHelpers.js'); module.exports = { publish (publishParams, fileName, fileType) { return new Promise((resolve, reject) => { - let publishResults = {}; - // 1. publish the file + let publishResults, certificateId, channelName; + // publish the file return lbryApi.publishClaim(publishParams) - // 2. upsert File record (update is in case the claim has been published before by this daemon) .then(tx => { logger.info(`Successfully published ${fileName}`, tx); publishResults = tx; + // get the channel information if (publishParams.channel_name) { logger.debug(`this claim was published in channel: ${publishParams.channel_name}`); return db.Channel.findOne({where: {channelName: publishParams.channel_name}}); @@ -22,13 +22,16 @@ module.exports = { } }) .then(channel => { - let certificateId = null; - let channelName = null; + certificateId = null; + channelName = null; if (channel) { certificateId = channel.channelClaimId; channelName = channel.channelName; } logger.debug(`certificateId: ${certificateId}`); + }) + .then(() => { + // create the File record const fileRecord = { name : publishParams.name, claimId : publishResults.claim_id, @@ -42,6 +45,7 @@ module.exports = { fileType, nsfw : publishParams.metadata.nsfw, }; + // create the Claim record const claimRecord = { name : publishParams.name, claimId : publishResults.claim_id, @@ -57,6 +61,7 @@ module.exports = { certificateId, channelName, }; + // upsert File record (update is in case the claim has been published before by this daemon) const upsertCriteria = { name : publishParams.name, claimId: publishResults.claim_id, diff --git a/models/index.js b/models/index.js index f8293431..62e4b23d 100644 --- a/models/index.js +++ b/models/index.js @@ -66,7 +66,7 @@ db.upsert = (Model, values, condition, tableName) => { } }) .catch(function (error) { - logger.error('Sequelize findOne error', error); + logger.error(`${tableName}.upsert error`, error); }); }; diff --git a/package.json b/package.json index 00b84557..9bf792f2 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,6 @@ "cookie-session": "^2.0.0-beta.3", "express": "^4.15.2", "express-handlebars": "^3.0.0", - "express-session": "^1.15.5", "form-data": "^2.3.1", "helmet": "^3.8.1", "mysql2": "^1.3.5", diff --git a/routes/api-routes.js b/routes/api-routes.js index 419ced91..edcc6cb7 100644 --- a/routes/api-routes.js +++ b/routes/api-routes.js @@ -1,6 +1,6 @@ const logger = require('winston'); const multipart = require('connect-multiparty'); -const multipartMiddleware = multipart(); +const multipartMiddleware = multipart({uploadDir: '/home/lbry/test/'}); const db = require('../models'); const { publish } = require('../controllers/publishController.js'); const { getClaimList, resolveUri } = require('../helpers/lbryApi.js'); @@ -73,6 +73,7 @@ module.exports = (app) => { // route to run a publish request on the daemon app.post('/api/publish', multipartMiddleware, ({ body, files, ip, originalUrl, user }, res) => { logger.debug('api/publish body:', body); + logger.debug('api/publish body:', files); let file, fileName, filePath, fileType, name, nsfw, license, title, description, thumbnail, anonymous, skipAuth, channelName, channelPassword; // validate that mandatory parts of the request are present try { @@ -84,7 +85,7 @@ module.exports = (app) => { } // validate file, name, license, and nsfw file = files.file; - fileName = file.name; + fileName = file.path.substring(file.path.lastIndexOf('/') + 1); filePath = file.path; fileType = file.type; name = body.name; -- 2.45.2 From 1f37c33206146cfd0f7613817dd17d9fde9f66f8 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 6 Nov 2017 14:22:00 -0800 Subject: [PATCH 2/5] updated comments --- controllers/publishController.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/controllers/publishController.js b/controllers/publishController.js index 5dd06482..d832c814 100644 --- a/controllers/publishController.js +++ b/controllers/publishController.js @@ -22,6 +22,7 @@ module.exports = { } }) .then(channel => { + // set channel information certificateId = null; channelName = null; if (channel) { @@ -61,12 +62,12 @@ module.exports = { certificateId, channelName, }; - // upsert File record (update is in case the claim has been published before by this daemon) + // upsert criteria const upsertCriteria = { name : publishParams.name, claimId: publishResults.claim_id, }; - // create the records + // upsert the records return Promise.all([db.upsert(db.File, fileRecord, upsertCriteria, 'File'), db.upsert(db.Claim, claimRecord, upsertCriteria, 'Claim')]); }) .then(([file, claim]) => { -- 2.45.2 From 40d40c22786d13bc338139ee51cadb72024591f4 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 6 Nov 2017 15:18:45 -0800 Subject: [PATCH 3/5] consolidated config to one config file --- .gitignore | 3 ++- config/custom-environment-variables.json | 15 ------------ config/default-0.json | 1 - config/default.json | 23 ------------------- config/development.json | 13 ----------- config/production.json | 13 ----------- .../{slackLoggerConfig.js => slackConfig.js} | 19 +++++++-------- config/speechConfig_example.js | 23 +++++++++++++++++++ controllers/statsController.js | 4 ++-- helpers/configVarCheck.js | 10 ++++---- helpers/handlebarsHelpers.js | 4 ++-- helpers/publishHelpers.js | 6 ++--- models/index.js | 8 +++---- public/assets/js/publishFileFunctions.js | 2 +- speech.js | 8 +++---- 15 files changed, 53 insertions(+), 99 deletions(-) delete mode 100644 config/custom-environment-variables.json delete mode 100644 config/default-0.json delete mode 100644 config/default.json delete mode 100644 config/development.json delete mode 100644 config/production.json rename config/{slackLoggerConfig.js => slackConfig.js} (59%) create mode 100644 config/speechConfig_example.js diff --git a/.gitignore b/.gitignore index 761ac590..bc72ae59 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules .idea -config/config.json \ No newline at end of file +config/config.json +config/speechConfig.js \ No newline at end of file diff --git a/config/custom-environment-variables.json b/config/custom-environment-variables.json deleted file mode 100644 index 78faebbf..00000000 --- a/config/custom-environment-variables.json +++ /dev/null @@ -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" - } -} \ No newline at end of file diff --git a/config/default-0.json b/config/default-0.json deleted file mode 100644 index 9e26dfee..00000000 --- a/config/default-0.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/config/default.json b/config/default.json deleted file mode 100644 index c5b65a20..00000000 --- a/config/default.json +++ /dev/null @@ -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 - } -} \ No newline at end of file diff --git a/config/development.json b/config/development.json deleted file mode 100644 index 4beca9ff..00000000 --- a/config/development.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "WalletConfig": { - "DefaultChannel": "@speechDev" - }, - "AnalyticsConfig":{ - "GoogleId": "UA-100747990-1" - }, - "Logging": { - "LogLevel": "silly", - "SlackErrorChannel": "#staging_speech-errors", - "SlackInfoChannel": "none" - } -} \ No newline at end of file diff --git a/config/production.json b/config/production.json deleted file mode 100644 index a5bc5074..00000000 --- a/config/production.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "WalletConfig": { - "DefaultChannel": "@speech" - }, - "AnalyticsConfig":{ - "GoogleId": "UA-60403362-3" - }, - "Logging": { - "LogLevel": "verbose", - "SlackErrorChannel": "#speech-errors", - "SlackInfoChannel": "#speech-logs" - } -} diff --git a/config/slackLoggerConfig.js b/config/slackConfig.js similarity index 59% rename from config/slackLoggerConfig.js rename to config/slackConfig.js index 4bd88200..74227bbd 100644 --- a/config/slackLoggerConfig.js +++ b/config/slackConfig.js @@ -1,29 +1,26 @@ -const config = require('config'); -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 config = require('./speechConfig.js'); const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook; module.exports = (winston) => { - if (SLACK_WEB_HOOK) { - // add a transport for errors to slack + if (config.logging.slackWebHook) { + // add a transport for errors to slack winston.add(winstonSlackWebHook, { name : 'slack-errors-transport', level : 'error', - webhookUrl: SLACK_WEB_HOOK, - channel : SLACK_ERROR_CHANNEL, + webhookUrl: config.logging.slackWebHook, + channel : config.logging.slackErrorChannel, username : 'spee.ch', iconEmoji : ':face_with_head_bandage:', }); winston.add(winstonSlackWebHook, { name : 'slack-info-transport', level : 'info', - webhookUrl: SLACK_WEB_HOOK, - channel : SLACK_INFO_CHANNEL, + webhookUrl: config.logging.slackWebHook, + channel : config.logging.slackInfoChannel, username : 'spee.ch', iconEmoji : ':nerd_face:', }); - // send test message + // send test message winston.error('Slack error logging is online.'); winston.info('Slack info logging is online.'); } else { diff --git a/config/speechConfig_example.js b/config/speechConfig_example.js new file mode 100644 index 00000000..d139c56c --- /dev/null +++ b/config/speechConfig_example.js @@ -0,0 +1,23 @@ +module.exports = { + wallet: { + lbryClaimAddress: null, + defaultChannel : null, + }, + analytics: { + googleId: null, + }, + sql: { + database: 'lbry', + username: null, + password: null, + }, + logging: { + logLevel : null, + slackWebHook : null, + slackErrorChannel: null, + slackInfoChannel : null, + }, + session: { + sessionKey: null, + }, +}; diff --git a/controllers/statsController.js b/controllers/statsController.js index 50dcc36d..6f3d4475 100644 --- a/controllers/statsController.js +++ b/controllers/statsController.js @@ -1,8 +1,8 @@ const logger = require('winston'); const ua = require('universal-analytics'); -const config = require('config'); +const config = require('../config/speechConfig.js'); const db = require('../models'); -const googleApiKey = config.get('AnalyticsConfig.GoogleId'); +const googleApiKey = config.analytics.googleId; module.exports = { postToStats (action, url, ipAddress, name, claimId, result) { diff --git a/helpers/configVarCheck.js b/helpers/configVarCheck.js index b4b40e51..b849245f 100644 --- a/helpers/configVarCheck.js +++ b/helpers/configVarCheck.js @@ -1,15 +1,13 @@ -const config = require('config'); +const config = require('../config/speechConfig.js'); const logger = require('winston'); -const fs = require('fs'); module.exports = function () { // get the config file - const defaultConfigFile = JSON.parse(fs.readFileSync('./config/default.json')); - for (let configCategoryKey in defaultConfigFile) { - if (defaultConfigFile.hasOwnProperty(configCategoryKey)) { + for (let configCategoryKey in config) { + if (config.hasOwnProperty(configCategoryKey)) { // get the final variables for each config category - const configVariables = config.get(configCategoryKey); + const configVariables = config[configCategoryKey]; for (let configVarKey in configVariables) { if (configVariables.hasOwnProperty(configVarKey)) { // print each variable diff --git a/helpers/handlebarsHelpers.js b/helpers/handlebarsHelpers.js index b4fb3c42..33ccb49d 100644 --- a/helpers/handlebarsHelpers.js +++ b/helpers/handlebarsHelpers.js @@ -1,10 +1,10 @@ const Handlebars = require('handlebars'); -const config = require('config'); +const config = require('../config/speechConfig.js'); module.exports = { // define any extra helpers you may need googleAnalytics () { - const googleApiKey = config.get('AnalyticsConfig.GoogleId'); + const googleApiKey = config.analytics.googleId; return new Handlebars.SafeString( `