updated publish flow and returned to image-size
This commit is contained in:
parent
0037addcda
commit
3a46a3714e
3 changed files with 40 additions and 33 deletions
|
@ -47,29 +47,38 @@ const authenticateChannelCredentials = (channelName, channelId, userPassword) =>
|
|||
};
|
||||
|
||||
const authenticateUser = (channelName, channelId, channelPassword, user) => {
|
||||
// case: no channelName or channel Id are provided (anonymous), regardless of whether user token is provided
|
||||
if (!channelName && !channelId) {
|
||||
return {
|
||||
channelName : null,
|
||||
channelClaimId: null,
|
||||
};
|
||||
}
|
||||
// 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');
|
||||
return new Promise((resolve, reject) => {
|
||||
// case: no channelName or channel Id are provided (anonymous), regardless of whether user token is provided
|
||||
if (!channelName && !channelId) {
|
||||
resolve({
|
||||
channelName : null,
|
||||
channelClaimId: null,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (channelId && channelId !== user.channelClaimId) {
|
||||
throw new Error('the provided channel id does not match user credentials');
|
||||
// case: channelName or channel Id are provided with user token
|
||||
if (user) {
|
||||
if (channelName && channelName !== user.channelName) {
|
||||
reject(new Error('the provided channel name does not match user credentials'));
|
||||
return;
|
||||
}
|
||||
if (channelId && channelId !== user.channelClaimId) {
|
||||
reject(new Error('the provided channel id does not match user credentials'));
|
||||
return;
|
||||
}
|
||||
resolve({
|
||||
channelName : user.channelName,
|
||||
channelClaimId: user.channelClaimId,
|
||||
});
|
||||
return;
|
||||
}
|
||||
return {
|
||||
channelName : user.channelName,
|
||||
channelClaimId: user.channelClaimId,
|
||||
};
|
||||
}
|
||||
// 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);
|
||||
// case: channelName or channel Id are provided with password instead of user token
|
||||
if (!channelPassword) {
|
||||
reject(new Error('no channel password provided'));
|
||||
return;
|
||||
}
|
||||
resolve(authenticateChannelCredentials(channelName, channelId, channelPassword));
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = authenticateUser;
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue