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) => {
|
const authenticateUser = (channelName, channelId, channelPassword, user) => {
|
||||||
// case: no channelName or channel Id are provided (anonymous), regardless of whether user token is provided
|
return new Promise((resolve, reject) => {
|
||||||
if (!channelName && !channelId) {
|
// case: no channelName or channel Id are provided (anonymous), regardless of whether user token is provided
|
||||||
return {
|
if (!channelName && !channelId) {
|
||||||
channelName : null,
|
resolve({
|
||||||
channelClaimId: null,
|
channelName : null,
|
||||||
};
|
channelClaimId: null,
|
||||||
}
|
});
|
||||||
// case: channelName or channel Id are provided with user token
|
return;
|
||||||
if (user) {
|
|
||||||
if (channelName && channelName !== user.channelName) {
|
|
||||||
throw new Error('the provided channel name does not match user credentials');
|
|
||||||
}
|
}
|
||||||
if (channelId && channelId !== user.channelClaimId) {
|
// case: channelName or channel Id are provided with user token
|
||||||
throw new Error('the provided channel id does not match user credentials');
|
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 {
|
// case: channelName or channel Id are provided with password instead of user token
|
||||||
channelName : user.channelName,
|
if (!channelPassword) {
|
||||||
channelClaimId: user.channelClaimId,
|
reject(new Error('no channel password provided'));
|
||||||
};
|
return;
|
||||||
}
|
}
|
||||||
// case: channelName or channel Id are provided with password instead of user token
|
resolve(authenticateChannelCredentials(channelName, channelId, channelPassword));
|
||||||
if (!channelPassword) throw new Error('no channel password provided');
|
});
|
||||||
return authenticateChannelCredentials(channelName, channelId, channelPassword);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = authenticateUser;
|
module.exports = authenticateUser;
|
||||||
|
|
|
@ -54,8 +54,6 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res)
|
||||||
// check channel authorization
|
// check channel authorization
|
||||||
authenticateUser(channelName, channelId, channelPassword, user)
|
authenticateUser(channelName, channelId, channelPassword, user)
|
||||||
.then(({ channelName, channelClaimId }) => {
|
.then(({ channelName, channelClaimId }) => {
|
||||||
// add channel details to the publish params
|
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
checkClaimAvailability(name),
|
checkClaimAvailability(name),
|
||||||
createPublishParams(filePath, name, title, description, license, nsfw, thumbnail, channelName, channelClaimId),
|
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 ]) => {
|
.then(([ claimAvailable, publishParams, thumbnailPublishParams ]) => {
|
||||||
if (!claimAvailabile) {
|
if (!claimAvailable) {
|
||||||
throw {
|
throw {
|
||||||
name: CLAIM_TAKEN,
|
name: CLAIM_TAKEN,
|
||||||
message: 'That claim name is already 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) => {
|
const getImageMetadata = (filePath) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
im.readMetadata(filePath, (err, metadata) => {
|
imageMagick.readMetadata(filePath, (err, metadata) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +14,7 @@ const getImageMetadata = (filePath) => {
|
||||||
|
|
||||||
const getImageDetails = (filePath) => {
|
const getImageDetails = (filePath) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
im.identify(filePath, (err, details) => {
|
imageMagick.identify(filePath, (err, details) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
|
@ -24,13 +25,12 @@ const getImageDetails = (filePath) => {
|
||||||
|
|
||||||
const getImageHeightAndWidth = (filePath) => {
|
const getImageHeightAndWidth = (filePath) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
im.identify(filePath, (err, details) => {
|
try {
|
||||||
if (err) {
|
const { height, width } = sizeOf(filePath);
|
||||||
reject(err);
|
|
||||||
}
|
|
||||||
const { height, width } = details;
|
|
||||||
resolve([height, width]);
|
resolve([height, width]);
|
||||||
});
|
} catch (error) {
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue