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;