Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudinary admin url update: fixes #2724 #4175

Merged
merged 1 commit into from
Sep 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion fields/components/columns/CloudinaryImageSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ var CloudinaryImageSummary = React.createClass({
},
renderImageThumbnail () {
if (!this.props.image) return;
const url = this.props.image.url.replace(/image\/upload/, `image/upload/c_thumb,g_face,h_${IMAGE_SIZE},w_${IMAGE_SIZE}`);
const startingUrl = this.props.secure ? this.props.image.secure_url : this.props.image.url;
const url = startingUrl.replace(/image\/upload/, `image/upload/c_thumb,g_face,h_${IMAGE_SIZE},w_${IMAGE_SIZE}`);
return <img src={url} style={imageStyle} className="img-load" />;
},
render () {
Expand Down
2 changes: 1 addition & 1 deletion fields/types/cloudinaryimage/CloudinaryImageColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var CloudinaryImageColumn = React.createClass({

return (
<ItemsTableValue field={this.props.col.type}>
<CloudinaryImageSummary label="dimensions" image={value} />
<CloudinaryImageSummary label="dimensions" image={value} secure={this.props.col.field.secure} />
</ItemsTableValue>
);

Expand Down
1 change: 1 addition & 0 deletions fields/types/cloudinaryimage/CloudinaryImageField.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ module.exports = Field.create({
crop: 'fit',
height: height,
format: 'jpg',
secure: this.props.secure,
});
}

Expand Down
15 changes: 15 additions & 0 deletions fields/types/cloudinaryimage/CloudinaryImageType.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,21 @@ cloudinaryimage.prototype.getData = function (item) {
return typeof value === 'object' ? value : {};
};

cloudinaryimage.prototype._originalGetOptions = cloudinaryimage.prototype.getOptions;

cloudinaryimage.prototype.getOptions = function () {
this._originalGetOptions();
// We are performing the check here, so that if cloudinary secure is added
// to keystone after the model is registered, it will still be respected.
// Setting secure overrides default `cloudinary secure`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've got me curious. What's the use case for setting secure/cloudinary secure after the models have been registered?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's mostly about the ordering of your keystone.js file. It is possible and valid to import your models and then after that line set cloudinary secure, however rather obtusely without checking again, you can end up not applying the option it looks like you set.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks for the explanation.

if ('secure' in this.options) {
this.__options.secure = this.options.secure;
} else if (keystone.get('cloudinary secure')) {
this.__options.secure = keystone.get('cloudinary secure');
}
return this.__options;
};

/**
* Detects whether the field has been modified
*/
Expand Down
4 changes: 2 additions & 2 deletions fields/types/cloudinaryimages/CloudinaryImagesColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var CloudinaryImagesColumn = React.createClass({
const items = [];
for (let i = 0; i < 3; i++) {
if (!value[i]) break;
items.push(<CloudinaryImageSummary key={'image' + i} image={value[i]} />);
items.push(<CloudinaryImageSummary key={'image' + i} image={value[i]} secure={this.props.col.field.secure} />);
}
if (value.length > 3) {
items.push(<span key="more" style={moreIndicatorStyle}>[...{value.length - 3} more]</span>);
Expand All @@ -29,7 +29,7 @@ var CloudinaryImagesColumn = React.createClass({
renderValue (value) {
if (!value || !Object.keys(value).length) return;

return <CloudinaryImageSummary image={value} />;
return <CloudinaryImageSummary image={value} secure={this.props.col.field.secure} />;

},
render () {
Expand Down
5 changes: 4 additions & 1 deletion fields/types/cloudinaryimages/CloudinaryImagesField.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ module.exports = Field.create({
imageSourceSmall: cloudinaryResize(img.public_id, {
...RESIZE_DEFAULTS,
height: 90,
secure: props.secure,
}),
imageSourceLarge: cloudinaryResize(img.public_id, {
...RESIZE_DEFAULTS,
height: 600,
width: 900,
secure: props.secure,
}),
}, index);
}) : [];
Expand Down Expand Up @@ -215,14 +217,15 @@ module.exports = Field.create({
}
},
renderLightbox () {
const { value } = this.props;
const { value, secure } = this.props;
if (!value || !value.length) return;

const images = value.map(image => ({
src: cloudinaryResize(image.public_id, {
...RESIZE_DEFAULTS,
height: 600,
width: 900,
secure,
}),
}));

Expand Down
16 changes: 16 additions & 0 deletions fields/types/cloudinaryimages/CloudinaryImagesType.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,22 @@ cloudinaryimages.prototype.inputIsValid = function (data) { // eslint-disable-li
return true;
};


cloudinaryimages.prototype._originalGetOptions = cloudinaryimages.prototype.getOptions;

cloudinaryimages.prototype.getOptions = function () {
this._originalGetOptions();
// We are performing the check here, so that if cloudinary secure is added
// to keystone after the model is registered, it will still be respected.
// Setting secure overrides default `cloudinary secure`
if ('secure' in this.options) {
this.__options.secure = this.options.secure;
} else if (keystone.get('cloudinary secure')) {
this.__options.secure = keystone.get('cloudinary secure');
}
return this.__options;
};

/**
* Updates the value for this field in the item from a data object
*/
Expand Down