Upload refactor #242
4 changed files with 13 additions and 15 deletions
|
@ -34,4 +34,12 @@ module.exports = {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
authenticateOrSkip (skipAuth, channelName, channelPassword) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (skipAuth) {
|
||||||
|
return resolve(true);
|
||||||
|
}
|
||||||
|
return resolve(module.exports.authenticateChannelCredentials(channelName, channelPassword));
|
||||||
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,7 +25,6 @@ module.exports = (sequelize, { STRING }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
User.prototype.comparePassword = function (password, callback) {
|
User.prototype.comparePassword = function (password, callback) {
|
||||||
logger.debug(`User.prototype.comparePassword ${password} ${this.password}`);
|
|
||||||
bcrypt.compare(password, this.password, callback);
|
bcrypt.compare(password, this.password, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ function getRequest (url) {
|
||||||
if ( xhttp.status == 200) {
|
if ( xhttp.status == 200) {
|
||||||
resolve(xhttp.response);
|
resolve(xhttp.response);
|
||||||
} else if (xhttp.status == 401) {
|
} else if (xhttp.status == 401) {
|
||||||
reject('Wrong username or password');
|
reject('Wrong channel name or password');
|
||||||
} else {
|
} else {
|
||||||
reject('request failed with status:' + xhttp.status);
|
reject('request failed with status:' + xhttp.status);
|
||||||
};
|
};
|
||||||
|
@ -29,7 +29,7 @@ function postRequest (url, params) {
|
||||||
if ( xhttp.status == 200) {
|
if ( xhttp.status == 200) {
|
||||||
resolve(xhttp.response);
|
resolve(xhttp.response);
|
||||||
} else if (xhttp.status == 401) {
|
} else if (xhttp.status == 401) {
|
||||||
reject( new AuthenticationError('Wrong username or password'));
|
reject( new AuthenticationError('Wrong channel name or password'));
|
||||||
} else {
|
} else {
|
||||||
reject('request failed with status:' + xhttp.status);
|
reject('request failed with status:' + xhttp.status);
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,14 +7,7 @@ const { getClaimList, resolveUri } = require('../helpers/lbryApi.js');
|
||||||
const { createPublishParams, validateApiPublishRequest, validatePublishSubmission, cleanseChannelName, checkClaimNameAvailability, checkChannelAvailability } = require('../helpers/publishHelpers.js');
|
const { createPublishParams, validateApiPublishRequest, validatePublishSubmission, cleanseChannelName, 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 { authenticateChannelCredentials } = require('../auth/authentication.js');
|
const { authenticateOrSkip } = require('../auth/authentication.js');
|
||||||
|
|
||||||
function authenticateOrSkip (skipAuth, channelName, channelPassword) {
|
|
||||||
if (skipAuth) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return authenticateChannelCredentials(channelName, channelPassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
||||||
|
@ -79,8 +72,6 @@ module.exports = (app) => {
|
||||||
});
|
});
|
||||||
// route to run a publish request on the daemon
|
// route to run a publish request on the daemon
|
||||||
app.post('/api/publish', multipartMiddleware, ({ body, files, ip, originalUrl, user }, res) => {
|
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;
|
let file, fileName, filePath, fileType, name, nsfw, license, title, description, thumbnail, anonymous, skipAuth, channelName, channelPassword;
|
||||||
// validate that mandatory parts of the request are present
|
// validate that mandatory parts of the request are present
|
||||||
try {
|
try {
|
||||||
|
@ -131,9 +122,9 @@ module.exports = (app) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
channelName = cleanseChannelName(channelName);
|
channelName = cleanseChannelName(channelName);
|
||||||
logger.debug(`name: ${name}, license: ${license} title: "${title}" description: "${description}" channelName: "${channelName}" channelPassword: "${channelPassword}" nsfw: "${nsfw}"`);
|
logger.debug(`/api/publish > name: ${name}, license: ${license} title: "${title}" description: "${description}" channelName: "${channelName}" channelPassword: "${channelPassword}" nsfw: "${nsfw}"`);
|
||||||
// check channel authorization
|
// check channel authorization
|
||||||
authenticateOrSkip(skipAuth)
|
authenticateOrSkip(skipAuth, channelName, channelPassword)
|
||||||
.then(authenticated => {
|
.then(authenticated => {
|
||||||
if (!authenticated) {
|
if (!authenticated) {
|
||||||
throw new Error('Authentication failed, you do not have access to that channel');
|
throw new Error('Authentication failed, you do not have access to that channel');
|
||||||
|
|
Loading…
Reference in a new issue