diff --git a/.gitignore b/.gitignore index b512c09d..63559f2b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules \ No newline at end of file +node_modules +ApiPublishTest.html \ No newline at end of file diff --git a/controllers/publishController.js b/controllers/publishController.js index b9daf2e0..51d5ddfc 100644 --- a/controllers/publishController.js +++ b/controllers/publishController.js @@ -46,14 +46,22 @@ module.exports = { nsfw : publishParams.metadata.nsfw, }, { name: publishParams.name, claimId: result.claim_id } - ).catch(error => { + ).then(() => { + // resolve the promise with the result from lbryApi.publishClaim; + resolve(result); + }) + .catch(error => { logger.error('Sequelize findOne error', error); + // reject the promise + reject(error); }); }) .catch(error => { logger.error(`Error publishing ${fileName}`, error); // delete the local file deleteTemporaryFile(publishParams.file_path); + // reject the promise + reject(error); }); }); return deferred; diff --git a/helpers/libraries/publishHelpers.js b/helpers/libraries/publishHelpers.js index c0f8be79..9bf8e857 100644 --- a/helpers/libraries/publishHelpers.js +++ b/helpers/libraries/publishHelpers.js @@ -6,6 +6,14 @@ const walletAddress = config.get('WalletConfig.LbryAddress'); module.exports = { createPublishParams (name, filePath, license, nsfw) { logger.debug(`Creating Publish Parameters for "${name}"`); + // ensure nsfw is a boolean + if (nsfw.toLowerCase === 'true') { + nsfw = true; + } else if (nsfw.toLowerCase === 'on') { + nsfw = true; + } else { + nsfw = false; + } const publishParams = { name, file_path: filePath, diff --git a/routes/api-routes.js b/routes/api-routes.js index a4dceb60..1912c097 100644 --- a/routes/api-routes.js +++ b/routes/api-routes.js @@ -34,11 +34,9 @@ module.exports = app => { // route to run a publish request on the daemon app.post('/api/publish', multipartMiddleware, ({ originalUrl, body, files }, res) => { logger.debug(`POST request on ${originalUrl}`); - console.log('>> req.files:', files); - console.log('>> req.body:', body); - const file = files.file1; + const file = files.file1 || files.null; if (!file) { - res.status(500).json({ 'error': 'No file was submitted. Form submission must have key "speechFile"' }); + res.status(500).json({ 'success': false, 'error': 'No file was submitted. Form submission must have key "speechFile"', 'data': null }); return; } const name = body.claim || file.name.substring(0, file.name.indexOf('.')); @@ -52,7 +50,6 @@ module.exports = app => { */ // prepare the publish parameters const publishParams = publishHelpers.createPublishParams(name, filePath, license, nsfw); - console.log('publish params', publishParams); // publish the file publishController .publish(publishParams, fileName, fileType) @@ -62,11 +59,5 @@ module.exports = app => { .catch(error => { errorHandlers.handleRequestError(error, res); }); - - // if (files) { - // res.status(200).json({'status': 'file(s) received'}); - // } else { - // res.status(400).josn({'status': 'no files(s) received'}); - // } }); }; diff --git a/uploadTest.html b/uploadTest.html deleted file mode 100644 index 16e7aae4..00000000 --- a/uploadTest.html +++ /dev/null @@ -1,17 +0,0 @@ - - -
- -