From 912363e936a5b82d3c57051f8d09ea8a1e0b85f4 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Tue, 7 Nov 2017 10:57:31 -0800 Subject: [PATCH 01/11] added sequelizeCli config example --- .gitignore | 2 +- .sequelizerc | 5 +++++ config/sequelizeCliConfig_example.js | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 .sequelizerc create mode 100644 config/sequelizeCliConfig_example.js diff --git a/.gitignore b/.gitignore index bc72ae59..356b3db2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ node_modules .idea -config/config.json +config/sequelizeCliConfig.js config/speechConfig.js \ No newline at end of file diff --git a/.sequelizerc b/.sequelizerc new file mode 100644 index 00000000..e671871a --- /dev/null +++ b/.sequelizerc @@ -0,0 +1,5 @@ +const path = require('path'); + +module.exports = { + 'config': path.resolve('config', 'sequelizeCliConfig.json'), +} \ No newline at end of file diff --git a/config/sequelizeCliConfig_example.js b/config/sequelizeCliConfig_example.js new file mode 100644 index 00000000..0b7e6b20 --- /dev/null +++ b/config/sequelizeCliConfig_example.js @@ -0,0 +1,23 @@ +module.exports = { + development: { + username: 'database_dev', + password: 'database_dev', + database: 'database_dev', + host : '127.0.0.1', + dialect : 'mysql', + }, + test: { + username: 'database_dev', + password: 'database_dev', + database: 'database_dev', + host : '127.0.0.1', + dialect : 'mysql', + }, + production: { + username: 'database_dev', + password: 'database_dev', + database: 'database_dev', + host : '127.0.0.1', + dialect : 'mysql', + }, +}; -- 2.45.3 From dce1c32288762f64540888b8d7fdf440a617edd2 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Tue, 7 Nov 2017 14:47:41 -0800 Subject: [PATCH 02/11] added migrations for Claim column types --- .sequelizerc | 2 +- ...meToClaim.js => ChangeAmountColumnType.js} | 14 ++++-- migrations/ChangeEffectiveAmountColumnType.js | 26 +++++++++++ migrations/ChangeHeightColumnType.js | 26 +++++++++++ migrations/ChangeValidAtHeightColumnType.js | 26 +++++++++++ migrations/UpdateUserPasswords5.js | 46 ------------------- 6 files changed, 88 insertions(+), 52 deletions(-) rename migrations/{AddChannelNameToClaim.js => ChangeAmountColumnType.js} (65%) create mode 100644 migrations/ChangeEffectiveAmountColumnType.js create mode 100644 migrations/ChangeHeightColumnType.js create mode 100644 migrations/ChangeValidAtHeightColumnType.js delete mode 100644 migrations/UpdateUserPasswords5.js diff --git a/.sequelizerc b/.sequelizerc index e671871a..f2daa0b6 100644 --- a/.sequelizerc +++ b/.sequelizerc @@ -1,5 +1,5 @@ const path = require('path'); module.exports = { - 'config': path.resolve('config', 'sequelizeCliConfig.json'), + 'config': path.resolve('config', 'sequelizeCliConfig.js'), } \ No newline at end of file diff --git a/migrations/AddChannelNameToClaim.js b/migrations/ChangeAmountColumnType.js similarity index 65% rename from migrations/AddChannelNameToClaim.js rename to migrations/ChangeAmountColumnType.js index b9ac1da8..434e10a3 100644 --- a/migrations/AddChannelNameToClaim.js +++ b/migrations/ChangeAmountColumnType.js @@ -1,11 +1,11 @@ module.exports = { up: (queryInterface, Sequelize) => { // logic for transforming into the new state - const p1 = queryInterface.addColumn( + const p1 = queryInterface.changeColumn( 'Claim', - 'channelName', + 'amount', { - type : Sequelize.STRING, + type : Sequelize.DOUBLE, allowNull: true, } ); @@ -13,9 +13,13 @@ module.exports = { }, down: (queryInterface, Sequelize) => { // logic for reverting the changes - const p1 = queryInterface.removeColumn( + const p1 = queryInterface.changeColumn( 'Claim', - 'channelName' + 'amount', + { + type : Sequelize.STRING, + allowNull: true, + } ); return Promise.all([p1]); }, diff --git a/migrations/ChangeEffectiveAmountColumnType.js b/migrations/ChangeEffectiveAmountColumnType.js new file mode 100644 index 00000000..63f48e15 --- /dev/null +++ b/migrations/ChangeEffectiveAmountColumnType.js @@ -0,0 +1,26 @@ +module.exports = { + up: (queryInterface, Sequelize) => { + // logic for transforming into the new state + const p1 = queryInterface.changeColumn( + 'Claim', + 'effectiveAmount', + { + type : Sequelize.DOUBLE, + allowNull: true, + } + ); + return Promise.all([p1]); + }, + down: (queryInterface, Sequelize) => { + // logic for reverting the changes + const p1 = queryInterface.changeColumn( + 'Claim', + 'effectiveAmount', + { + type : Sequelize.STRING, + allowNull: true, + } + ); + return Promise.all([p1]); + }, +}; diff --git a/migrations/ChangeHeightColumnType.js b/migrations/ChangeHeightColumnType.js new file mode 100644 index 00000000..c6d32223 --- /dev/null +++ b/migrations/ChangeHeightColumnType.js @@ -0,0 +1,26 @@ +module.exports = { + up: (queryInterface, Sequelize) => { + // logic for transforming into the new state + const p1 = queryInterface.changeColumn( + 'Claim', + 'height', + { + type : Sequelize.INTEGER, + allowNull: true, + } + ); + return Promise.all([p1]); + }, + down: (queryInterface, Sequelize) => { + // logic for reverting the changes + const p1 = queryInterface.changeColumn( + 'Claim', + 'height', + { + type : Sequelize.STRING, + allowNull: true, + } + ); + return Promise.all([p1]); + }, +}; diff --git a/migrations/ChangeValidAtHeightColumnType.js b/migrations/ChangeValidAtHeightColumnType.js new file mode 100644 index 00000000..3f87aa4c --- /dev/null +++ b/migrations/ChangeValidAtHeightColumnType.js @@ -0,0 +1,26 @@ +module.exports = { + up: (queryInterface, Sequelize) => { + // logic for transforming into the new state + const p1 = queryInterface.changeColumn( + 'Claim', + 'validAtHeight', + { + type : Sequelize.INTEGER, + allowNull: true, + } + ); + return Promise.all([p1]); + }, + down: (queryInterface, Sequelize) => { + // logic for reverting the changes + const p1 = queryInterface.changeColumn( + 'Claim', + 'validAtHeight', + { + type : Sequelize.STRING, + allowNull: true, + } + ); + return Promise.all([p1]); + }, +}; diff --git a/migrations/UpdateUserPasswords5.js b/migrations/UpdateUserPasswords5.js deleted file mode 100644 index f911c86e..00000000 --- a/migrations/UpdateUserPasswords5.js +++ /dev/null @@ -1,46 +0,0 @@ -const db = require('../models'); -const bcrypt = require('bcrypt'); -const logger = require('winston'); - -module.exports = { - up: (queryInterface, Sequelize) => { - // get all the users - return db.User - .findAll() - .then((users) => { - // create an array of promises, with each promise bcrypting a password and updating the record - const promises = users.map((record) => { - // bcrypt - // generate a salt string to use for hashing - return new Promise((resolve, reject) => { - bcrypt.genSalt((saltError, salt) => { - if (saltError) { - logger.error('salt error', saltError); - reject(saltError); - return; - } - // generate a hashed version of the user's password - bcrypt.hash(record.password, salt, (hashError, hash) => { - // if there is an error with the hash generation return the error - if (hashError) { - logger.error('hash error', hashError); - reject(hashError); - return; - } - // replace the password string with the hash password value - resolve(queryInterface.sequelize.query(`UPDATE User SET User.password = "${hash}" WHERE User.id = ${record.id}`)); - }); - }); - }); - }); - // return the array of promises - return Promise.all(promises); - }) - .catch(error => { - logger.error('error prepping promises array', error); - }); - }, - down: (queryInterface, Sequelize) => { - // logic for reverting the changes - }, -}; -- 2.45.3 From e49942344a7c1e7120cde79043c76096faaf71cf Mon Sep 17 00:00:00 2001 From: bill bittner Date: Tue, 7 Nov 2017 15:21:42 -0800 Subject: [PATCH 03/11] added migration for Certificate column types --- migrations/ChangeCertificateColumnTypes.js | 74 ++++++++++++++++++++++ models/claim.js | 10 +-- 2 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 migrations/ChangeCertificateColumnTypes.js diff --git a/migrations/ChangeCertificateColumnTypes.js b/migrations/ChangeCertificateColumnTypes.js new file mode 100644 index 00000000..95e62ebf --- /dev/null +++ b/migrations/ChangeCertificateColumnTypes.js @@ -0,0 +1,74 @@ +module.exports = { + up: (queryInterface, Sequelize) => { + // logic for transforming into the new state + const p1 = queryInterface.changeColumn( + 'Certificate', + 'amount', + { + type : Sequelize.DOUBLE, + allowNull: true, + } + ); + const p2 = queryInterface.changeColumn( + 'Certificate', + 'effectiveAmount', + { + type : Sequelize.DOUBLE, + allowNull: true, + } + ); + const p3 = queryInterface.changeColumn( + 'Certificate', + 'height', + { + type : Sequelize.INTEGER, + allowNull: true, + } + ); + const p4 = queryInterface.changeColumn( + 'Certificate', + 'validAtHeight', + { + type : Sequelize.INTEGER, + allowNull: true, + } + ); + return Promise.all([p1, p2, p3, p4]); + }, + down: (queryInterface, Sequelize) => { + // logic for reverting the changes + const p1 = queryInterface.changeColumn( + 'Certificate', + 'amount', + { + type : Sequelize.STRING, + allowNull: true, + } + ); + const p2 = queryInterface.changeColumn( + 'Certificate', + 'effectiveAmount', + { + type : Sequelize.STRING, + allowNull: true, + } + ); + const p3 = queryInterface.changeColumn( + 'Certificate', + 'height', + { + type : Sequelize.STRING, + allowNull: true, + } + ); + const p4 = queryInterface.changeColumn( + 'Certificate', + 'validAtHeight', + { + type : Sequelize.STRING, + allowNull: true, + } + ); + return Promise.all([p1, p2, p3, p4]); + }, +}; diff --git a/models/claim.js b/models/claim.js index 7145e9e0..992a7158 100644 --- a/models/claim.js +++ b/models/claim.js @@ -25,7 +25,7 @@ function sortResult (result, longId) { return shortId; } -module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, DOUBLE, Op }) => { +module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DOUBLE }) => { const Claim = sequelize.define( 'Claim', { @@ -34,7 +34,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D default: null, }, amount: { - type : STRING, + type : DOUBLE, default: null, }, claimId: { @@ -54,7 +54,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D default: null, }, effectiveAmount: { - type : STRING, + type : DOUBLE, default: null, }, hasSignature: { @@ -62,7 +62,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D default: null, }, height: { - type : STRING, + type : INTEGER, default: null, }, hex: { @@ -82,7 +82,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D default: null, }, validAtHeight: { - type : STRING, + type : INTEGER, default: null, }, outpoint: { -- 2.45.3 From 1b61e0fefa38d3630d1ce9c2a1cc08f860d82fe7 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Tue, 7 Nov 2017 15:42:48 -0800 Subject: [PATCH 04/11] updated Certificate model to match migration --- models/certificate.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/models/certificate.js b/models/certificate.js index b68d6df5..7fd1ca3a 100644 --- a/models/certificate.js +++ b/models/certificate.js @@ -34,7 +34,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D default: null, }, amount: { - type : STRING, + type : DOUBLE, default: null, }, claimId: { @@ -54,7 +54,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D default: null, }, effectiveAmount: { - type : STRING, + type : DOUBLE, default: null, }, hasSignature: { @@ -62,7 +62,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D default: null, }, height: { - type : STRING, + type : INTEGER, default: null, }, hex: { @@ -82,7 +82,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D default: null, }, validAtHeight: { - type : STRING, + type : INTEGER, default: null, }, outpoint: { -- 2.45.3 From 37315c6c6687228c9282a331311cd99017bcb8ff Mon Sep 17 00:00:00 2001 From: bill bittner Date: Tue, 7 Nov 2017 16:15:12 -0800 Subject: [PATCH 05/11] added upload path to config and removed socket.io ref --- config/speechConfig_example.js | 3 +++ routes/api-routes.js | 3 ++- speech.js | 4 +--- views/index.handlebars | 6 +++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/config/speechConfig_example.js b/config/speechConfig_example.js index d10745a3..f485fb34 100644 --- a/config/speechConfig_example.js +++ b/config/speechConfig_example.js @@ -19,4 +19,7 @@ module.exports = { session: { sessionKey: null, // enter a secret key to be used for session encryption }, + files: { + uploadDirectory: null, // enter file path to where uploads/publishes should be stored + }, }; diff --git a/routes/api-routes.js b/routes/api-routes.js index edcc6cb7..e8e28b71 100644 --- a/routes/api-routes.js +++ b/routes/api-routes.js @@ -1,6 +1,7 @@ const logger = require('winston'); const multipart = require('connect-multiparty'); -const multipartMiddleware = multipart({uploadDir: '/home/lbry/test/'}); +const config = require('../config/speechConfig.js'); +const multipartMiddleware = multipart({uploadDir: config.files.uploadDirectory}); const db = require('../models'); const { publish } = require('../controllers/publishController.js'); const { getClaimList, resolveUri } = require('../helpers/lbryApi.js'); diff --git a/speech.js b/speech.js index 19253e10..7e7a4e5f 100644 --- a/speech.js +++ b/speech.js @@ -1,7 +1,6 @@ // load dependencies const express = require('express'); const bodyParser = require('body-parser'); -const siofu = require('socketio-file-upload'); const expressHandlebars = require('express-handlebars'); const Handlebars = require('handlebars'); const handlebarsHelpers = require('./helpers/handlebarsHelpers.js'); @@ -32,7 +31,6 @@ app.use(helmet()); // set HTTP headers to protect against well-known web vulnera app.use(express.static(`${__dirname}/public`)); // 'express.static' to serve static files from public directory app.use(bodyParser.json()); // 'body parser' for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); // 'body parser' for parsing application/x-www-form-urlencoded -app.use(siofu.router); // 'socketio-file-upload' router for uploading with socket.io app.use((req, res, next) => { // custom logging middleware to log all incoming http requests logger.verbose(`Request on ${req.originalUrl} from ${req.ip}`); logger.debug('req.body:', req.body); @@ -76,7 +74,7 @@ db.sequelize .then(hostedContentPath => { // add the hosted content folder at a static path app.use('/media', express.static(hostedContentPath)); - // require routes & wrap in socket.io + // require routes require('./routes/auth-routes.js')(app); require('./routes/api-routes.js')(app); require('./routes/page-routes.js')(app); diff --git a/views/index.handlebars b/views/index.handlebars index 09c01c0e..0b09d8a6 100644 --- a/views/index.handlebars +++ b/views/index.handlebars @@ -1,8 +1,8 @@
- +
-
+

Drag & drop image or video here to publish

@@ -22,7 +22,7 @@
-
+