updated publish flow and returned to image-size

This commit is contained in:
bill bittner 2018-07-27 12:31:08 -07:00
parent 0037addcda
commit 3a46a3714e
3 changed files with 40 additions and 33 deletions

View file

@ -47,29 +47,38 @@ const authenticateChannelCredentials = (channelName, channelId, userPassword) =>
};
const authenticateUser = (channelName, channelId, channelPassword, user) => {
return new Promise((resolve, reject) => {
// case: no channelName or channel Id are provided (anonymous), regardless of whether user token is provided
if (!channelName && !channelId) {
return {
resolve({
channelName : null,
channelClaimId: null,
};
});
return;
}
// case: channelName or channel Id are provided with user token
if (user) {
if (channelName && channelName !== user.channelName) {
throw new Error('the provided channel name does not match user credentials');
reject(new Error('the provided channel name does not match user credentials'));
return;
}
if (channelId && channelId !== user.channelClaimId) {
throw new Error('the provided channel id does not match user credentials');
reject(new Error('the provided channel id does not match user credentials'));
return;
}
return {
resolve({
channelName : user.channelName,
channelClaimId: user.channelClaimId,
};
});
return;
}
// case: channelName or channel Id are provided with password instead of user token
if (!channelPassword) throw new Error('no channel password provided');
return authenticateChannelCredentials(channelName, channelId, channelPassword);
if (!channelPassword) {
reject(new Error('no channel password provided'));
return;
}
resolve(authenticateChannelCredentials(channelName, channelId, channelPassword));
});
};
module.exports = authenticateUser;

View file

@ -54,8 +54,6 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res)
// check channel authorization
authenticateUser(channelName, channelId, channelPassword, user)
.then(({ channelName, channelClaimId }) => {
// add channel details to the publish params
return Promise.all([
checkClaimAvailability(name),
createPublishParams(filePath, name, title, description, license, nsfw, thumbnail, channelName, channelClaimId),
@ -63,7 +61,7 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res)
])
})
.then(([ claimAvailable, publishParams, thumbnailPublishParams ]) => {
if (!claimAvailabile) {
if (!claimAvailable) {
throw {
name: CLAIM_TAKEN,
message: 'That claim name is already taken'

View file

@ -1,8 +1,9 @@
const im = require('imagemagick');
const imageMagick = require('imagemagick');
const sizeOf = require('image-size');
const getImageMetadata = (filePath) => {
return new Promise((resolve, reject) => {
im.readMetadata(filePath, (err, metadata) => {
imageMagick.readMetadata(filePath, (err, metadata) => {
if (err) {
reject(err);
}
@ -13,7 +14,7 @@ const getImageMetadata = (filePath) => {
const getImageDetails = (filePath) => {
return new Promise((resolve, reject) => {
im.identify(filePath, (err, details) => {
imageMagick.identify(filePath, (err, details) => {
if (err) {
reject(err);
}
@ -24,13 +25,12 @@ const getImageDetails = (filePath) => {
const getImageHeightAndWidth = (filePath) => {
return new Promise((resolve, reject) => {
im.identify(filePath, (err, details) => {
if (err) {
reject(err);
}
const { height, width } = details;
try {
const { height, width } = sizeOf(filePath);
resolve([height, width]);
});
} catch (error) {
reject(error);
}
});
};