Merge pull request #3691 from DKvistgaard/bugfix/cloudinary-delete-resource-type

Fix Cloudinary deletion of other files than images
This commit is contained in:
Alexandre BODIN 2019-10-04 14:44:09 +02:00 committed by GitHub
commit 1a49d1a51e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 39 deletions

View File

@ -11,11 +11,12 @@ import PropTypes from 'prop-types';
import styles from './styles.scss';
class GlobalPagination extends React.Component {
getLastPageNumber = () => Math.ceil(this.props.count / this.props.params._limit) || 1;
getLastPageNumber = () =>
Math.ceil(this.props.count / this.props.params._limit) || 1;
handleDotsClick = (e) => e.preventDefault();
handleDotsClick = e => e.preventDefault();
handlePreviousPageClick = (e) => {
handlePreviousPageClick = e => {
e.preventDefault();
if (!this.isFirstPage()) {
@ -25,9 +26,9 @@ class GlobalPagination extends React.Component {
};
this.props.onChangeParams({ target });
}
}
};
handleNextPageClick = (e) => {
handleNextPageClick = e => {
e.preventDefault();
if (!this.isLastPage()) {
@ -37,31 +38,32 @@ class GlobalPagination extends React.Component {
};
this.props.onChangeParams({ target });
}
}
};
handleFirstPageClick = (e) => {
handleFirstPageClick = e => {
e.preventDefault();
const target = {
name: 'params._page',
value: 1,
};
this.props.onChangeParams({ target });
}
};
handleLastPageClick = (e) => {
handleLastPageClick = e => {
e.preventDefault();
const target = {
name: 'params._page',
value: this.getLastPageNumber(),
};
this.props.onChangeParams({ target });
}
};
isFirstPage = () => this.props.params._page === 1;
isLastPage = () => this.props.params._page === this.getLastPageNumber();
needAfterLinksDots = () => this.props.params._page < this.getLastPageNumber() - 1;
needAfterLinksDots = () =>
this.props.params._page < this.getLastPageNumber() - 1;
needPreviousLinksDots = () => this.props.params._page > 3;
@ -111,19 +113,18 @@ class GlobalPagination extends React.Component {
}
// Generate links
return (
map(linksOptions, (linksOption, key) => (
<li
className={`${linksOption.isActive && styles.navLiActive}`}
key={key}
return map(linksOptions, (linksOption, key) => (
<li className={`${linksOption.isActive && styles.navLiActive}`} key={key}>
<a
href=""
disabled={linksOption.isActive}
onClick={linksOption.handleClick}
>
<a href="" disabled={linksOption.isActive} onClick={linksOption.handleClick}>
{linksOption.value}
</a>
</li>
))
);
}
{linksOption.value}
</a>
</li>
));
};
render() {
return (
@ -141,9 +142,7 @@ class GlobalPagination extends React.Component {
<i className="fa fa-angle-left" aria-hidden="true"></i>
</a>
<nav className={styles.nav}>
<ul className={styles.navUl}>
{this.renderLinks()}
</ul>
<ul className={styles.navUl}>{this.renderLinks()}</ul>
</nav>
<a
href=""
@ -172,16 +171,10 @@ GlobalPagination.defaultProps = {
};
GlobalPagination.propTypes = {
count: PropTypes.oneOfType([
PropTypes.number,
PropTypes.bool,
]),
count: PropTypes.oneOfType([PropTypes.number, PropTypes.bool]),
onChangeParams: PropTypes.func,
params: PropTypes.shape({
_page: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
_page: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
_limit: PropTypes.number,
}),
};

View File

@ -46,8 +46,8 @@
"configurable": false,
"required": true
},
"public_id": {
"type": "string",
"provider_metadata": {
"type": "json",
"configurable": false
},
"related": {

View File

@ -42,18 +42,23 @@ module.exports = {
if (err) {
return reject(err);
}
file.public_id = image.public_id;
file.url = image.secure_url;
file.provider_metadata = {
public_id: image.public_id,
resource_type: image.resource_type,
};
resolve();
},
}
);
intoStream(file.buffer).pipe(upload_stream);
});
},
async delete(file) {
try {
const response = await cloudinary.uploader.destroy(file.public_id, {
const { resource_type, public_id } = file.provider_metadata;
const response = await cloudinary.uploader.destroy(public_id, {
invalidate: true,
resource_type: resource_type || 'image',
});
if (response.result !== 'ok') {
throw {