updated api publish route
This commit is contained in:
parent
f0914ce983
commit
bd2a48f883
7 changed files with 80 additions and 27 deletions
|
@ -1,5 +1,33 @@
|
||||||
module.exports = {
|
const db = require('../models');
|
||||||
isAuthenticated (req, res, next) {
|
const logger = require('winston');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
authenticateApiPublish (username, password) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (username === 'none') {
|
||||||
|
resolve(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
db.User
|
||||||
|
.findOne({where: {userName: username}})
|
||||||
|
.then(user => {
|
||||||
|
if (!user) {
|
||||||
|
logger.debug('no user found');
|
||||||
|
resolve(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!user.validPassword(password, user.password)) {
|
||||||
|
logger.debug('incorrect password');
|
||||||
|
resolve(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
logger.debug('user found:', user.dataValues);
|
||||||
|
resolve(true);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
logger.error(error);
|
||||||
|
reject();
|
||||||
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -97,7 +97,7 @@ function getAssetByLongClaimId (fullClaimId, name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function chooseThumbnail (claimInfo, defaultThumbnail) {
|
function chooseThumbnail (claimInfo, defaultThumbnail) {
|
||||||
if (!claimInfo.thumbnail || claimInfo.thumbnail === '') {
|
if (!claimInfo.thumbnail || claimInfo.thumbnail.trim() === '') {
|
||||||
return defaultThumbnail;
|
return defaultThumbnail;
|
||||||
}
|
}
|
||||||
return claimInfo.thumbnail;
|
return claimInfo.thumbnail;
|
||||||
|
@ -168,7 +168,12 @@ module.exports = {
|
||||||
element['thumbnail'] = chooseThumbnail(element, DEFAULT_THUMBNAIL);
|
element['thumbnail'] = chooseThumbnail(element, DEFAULT_THUMBNAIL);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return resolve(allChannelClaims);
|
return resolve({
|
||||||
|
channelName,
|
||||||
|
longChannelId,
|
||||||
|
shortChannelId,
|
||||||
|
claims: allChannelClaims,
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
reject(error);
|
reject(error);
|
||||||
|
|
|
@ -57,22 +57,20 @@ module.exports = {
|
||||||
// filter nsfw and ensure it is a boolean
|
// filter nsfw and ensure it is a boolean
|
||||||
if (nsfw === false) {
|
if (nsfw === false) {
|
||||||
nsfw = false;
|
nsfw = false;
|
||||||
} else if (nsfw.toLowerCase === 'false') {
|
} else if (typeof nsfw === 'string') {
|
||||||
nsfw = false;
|
if (nsfw.toLowerCase === 'false' || nsfw.toLowerCase === 'off' || nsfw === '0') {
|
||||||
} else if (nsfw.toLowerCase === 'off') {
|
|
||||||
nsfw = false;
|
nsfw = false;
|
||||||
|
}
|
||||||
} else if (nsfw === 0) {
|
} else if (nsfw === 0) {
|
||||||
nsfw = false;
|
nsfw = false;
|
||||||
} else if (nsfw === '0') {
|
|
||||||
nsfw = false;
|
|
||||||
} else {
|
} else {
|
||||||
nsfw = true;
|
nsfw = true;
|
||||||
}
|
}
|
||||||
// provide defaults for title & description
|
// provide defaults for title & description
|
||||||
if (title === '' || title === null) {
|
if (title === null || title === '') {
|
||||||
title = name;
|
title = name;
|
||||||
}
|
}
|
||||||
if (description.trim() === '' || description === null) {
|
if (description === null || description.trim() === '') {
|
||||||
description = `${name} published via spee.ch`;
|
description = `${name} published via spee.ch`;
|
||||||
}
|
}
|
||||||
// create the publish params
|
// create the publish params
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
|
|
||||||
|
/* GENERAL */
|
||||||
|
|
||||||
|
|
||||||
/* TEXT */
|
/* TEXT */
|
||||||
|
|
||||||
body, button, input, textarea, label, select, option {
|
body, button, input, textarea, label, select, option {
|
||||||
|
@ -32,6 +35,14 @@ h2 {
|
||||||
padding: 6px;
|
padding: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
color: black;;
|
||||||
|
}
|
||||||
|
|
||||||
|
.h3--secondary {
|
||||||
|
color: #999999;
|
||||||
|
}
|
||||||
|
|
||||||
h4 {
|
h4 {
|
||||||
padding: 3px;
|
padding: 3px;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ const { getClaimList, resolveUri } = require('../helpers/lbryApi.js');
|
||||||
const { createPublishParams, validateFile, checkClaimNameAvailability, checkChannelAvailability } = require('../helpers/publishHelpers.js');
|
const { createPublishParams, validateFile, checkClaimNameAvailability, checkChannelAvailability } = require('../helpers/publishHelpers.js');
|
||||||
const errorHandlers = require('../helpers/errorHandlers.js');
|
const errorHandlers = require('../helpers/errorHandlers.js');
|
||||||
const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
|
const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
|
||||||
|
const { authenticateApiPublish } = require('../auth/authentication.js');
|
||||||
|
|
||||||
module.exports = (app) => {
|
module.exports = (app) => {
|
||||||
// route to run a claim_list request on the daemon
|
// route to run a claim_list request on the daemon
|
||||||
|
@ -76,8 +77,13 @@ module.exports = (app) => {
|
||||||
// validate that a file was provided
|
// validate that a file was provided
|
||||||
const file = files.speech || files.null;
|
const file = files.speech || files.null;
|
||||||
const name = body.name || file.name.substring(0, file.name.indexOf('.'));
|
const name = body.name || file.name.substring(0, file.name.indexOf('.'));
|
||||||
|
const title = body.title || null;
|
||||||
|
const description = body.description || null;
|
||||||
const license = body.license || 'No License Provided';
|
const license = body.license || 'No License Provided';
|
||||||
const nsfw = body.nsfw || true;
|
const nsfw = body.nsfw || null;
|
||||||
|
const channelName = body.channelName || 'none';
|
||||||
|
const channelPassword = body.channelPassword || null;
|
||||||
|
logger.debug(`name: ${name}, license: ${license}, nsfw: ${nsfw}`);
|
||||||
try {
|
try {
|
||||||
validateFile(file, name, license, nsfw);
|
validateFile(file, name, license, nsfw);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -86,19 +92,27 @@ module.exports = (app) => {
|
||||||
res.status(400).send(error.message);
|
res.status(400).send(error.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// prepare the publish parameters
|
|
||||||
const fileName = file.name;
|
const fileName = file.name;
|
||||||
const filePath = file.path;
|
const filePath = file.path;
|
||||||
const fileType = file.type;
|
const fileType = file.type;
|
||||||
const publishParams = createPublishParams(name, filePath, license, nsfw);
|
// channel authorization
|
||||||
// publish the file
|
authenticateApiPublish(channelName, channelPassword)
|
||||||
publish(publishParams, fileName, fileType)
|
.then(result => {
|
||||||
|
if (!result) {
|
||||||
|
res.status(401).send('Authentication failed, you do not have access to that channel');
|
||||||
|
throw new Error('authentication failed');
|
||||||
|
}
|
||||||
|
return createPublishParams(name, filePath, title, description, license, nsfw, channelName);
|
||||||
|
})
|
||||||
|
.then(publishParams => {
|
||||||
|
return publish(publishParams, fileName, fileType);
|
||||||
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
postToStats('publish', originalUrl, ip, null, null, 'success');
|
postToStats('publish', originalUrl, ip, null, null, 'success');
|
||||||
res.status(200).json(result);
|
res.status(200).json(result);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
errorHandlers.handleRequestError('publish', originalUrl, ip, error, res);
|
logger.error('publish api error', error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -124,15 +124,12 @@ module.exports = (app) => {
|
||||||
// 1. retrieve the channel contents
|
// 1. retrieve the channel contents
|
||||||
getChannelContents(channelName, channelId)
|
getChannelContents(channelName, channelId)
|
||||||
// 2. respond to the request
|
// 2. respond to the request
|
||||||
.then(channelContents => {
|
.then(result => {
|
||||||
if (!channelContents) {
|
logger.debug('result');
|
||||||
|
if (!result.claims) {
|
||||||
res.status(200).render('noChannel');
|
res.status(200).render('noChannel');
|
||||||
} else {
|
} else {
|
||||||
const handlebarsData = {
|
res.status(200).render('channel', result);
|
||||||
channelName,
|
|
||||||
channelContents,
|
|
||||||
};
|
|
||||||
res.status(200).render('channel', handlebarsData);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
{{> topBar}}
|
{{> topBar}}
|
||||||
<div>
|
<div>
|
||||||
<h3>{{this.channelName}}</h3>
|
<h3>{{this.channelName}}<span class="h3--secondary">:{{this.shortChannelId}}</span></h3>
|
||||||
<p>Below is all the free content in this channel.</p>
|
<p>Below is all the free content in this channel.</p>
|
||||||
{{#each channelContents}}
|
{{#each this.claims}}
|
||||||
{{> contentListItem}}
|
{{> contentListItem}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue