tested publishing
This commit is contained in:
parent
edeb933f8a
commit
6170be4978
5 changed files with 21 additions and 30 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
node_modules
|
||||
node_modules
|
||||
ApiPublishTest.html
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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'});
|
||||
// }
|
||||
});
|
||||
};
|
||||
|
|
|
@ -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ω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>
|
Loading…
Reference in a new issue