tested publishing

This commit is contained in:
bill bittner 2017-06-26 15:01:41 -07:00
parent edeb933f8a
commit 6170be4978
5 changed files with 21 additions and 30 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
node_modules
ApiPublishTest.html

View file

@ -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;

View file

@ -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,

View file

@ -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'});
// }
});
};

View file

@ -1,17 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>upload</title>
</head>
<body>
<form action="http://localhost:3000/api/publish" method="post" enctype="multipart/form-data">
<p><input type="text" name="text1" value="text default">
<p><input type="text" name="text2" value="a&#x03C9;b">
<p><input type="file" name="file1">
<p><input type="file" name="file2">
<p><input type="file" name="file3">
<p><button type="submit">Submit</button>
</form>
</body>
</html>