mirror of
https://github.com/strapi/strapi.git
synced 2025-11-17 18:51:22 +00:00
Merge pull request #3691 from DKvistgaard/bugfix/cloudinary-delete-resource-type
Fix Cloudinary deletion of other files than images
This commit is contained in:
commit
1a49d1a51e
@ -11,11 +11,12 @@ import PropTypes from 'prop-types';
|
|||||||
import styles from './styles.scss';
|
import styles from './styles.scss';
|
||||||
|
|
||||||
class GlobalPagination extends React.Component {
|
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();
|
e.preventDefault();
|
||||||
|
|
||||||
if (!this.isFirstPage()) {
|
if (!this.isFirstPage()) {
|
||||||
@ -25,9 +26,9 @@ class GlobalPagination extends React.Component {
|
|||||||
};
|
};
|
||||||
this.props.onChangeParams({ target });
|
this.props.onChangeParams({ target });
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
handleNextPageClick = (e) => {
|
handleNextPageClick = e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (!this.isLastPage()) {
|
if (!this.isLastPage()) {
|
||||||
@ -37,31 +38,32 @@ class GlobalPagination extends React.Component {
|
|||||||
};
|
};
|
||||||
this.props.onChangeParams({ target });
|
this.props.onChangeParams({ target });
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
handleFirstPageClick = (e) => {
|
handleFirstPageClick = e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const target = {
|
const target = {
|
||||||
name: 'params._page',
|
name: 'params._page',
|
||||||
value: 1,
|
value: 1,
|
||||||
};
|
};
|
||||||
this.props.onChangeParams({ target });
|
this.props.onChangeParams({ target });
|
||||||
}
|
};
|
||||||
|
|
||||||
handleLastPageClick = (e) => {
|
handleLastPageClick = e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const target = {
|
const target = {
|
||||||
name: 'params._page',
|
name: 'params._page',
|
||||||
value: this.getLastPageNumber(),
|
value: this.getLastPageNumber(),
|
||||||
};
|
};
|
||||||
this.props.onChangeParams({ target });
|
this.props.onChangeParams({ target });
|
||||||
}
|
};
|
||||||
|
|
||||||
isFirstPage = () => this.props.params._page === 1;
|
isFirstPage = () => this.props.params._page === 1;
|
||||||
|
|
||||||
isLastPage = () => this.props.params._page === this.getLastPageNumber();
|
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;
|
needPreviousLinksDots = () => this.props.params._page > 3;
|
||||||
|
|
||||||
@ -111,19 +113,18 @@ class GlobalPagination extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate links
|
// Generate links
|
||||||
return (
|
return map(linksOptions, (linksOption, key) => (
|
||||||
map(linksOptions, (linksOption, key) => (
|
<li className={`${linksOption.isActive && styles.navLiActive}`} key={key}>
|
||||||
<li
|
<a
|
||||||
className={`${linksOption.isActive && styles.navLiActive}`}
|
href=""
|
||||||
key={key}
|
disabled={linksOption.isActive}
|
||||||
|
onClick={linksOption.handleClick}
|
||||||
>
|
>
|
||||||
<a href="" disabled={linksOption.isActive} onClick={linksOption.handleClick}>
|
|
||||||
{linksOption.value}
|
{linksOption.value}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
))
|
));
|
||||||
);
|
};
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
@ -141,9 +142,7 @@ class GlobalPagination extends React.Component {
|
|||||||
<i className="fa fa-angle-left" aria-hidden="true"></i>
|
<i className="fa fa-angle-left" aria-hidden="true"></i>
|
||||||
</a>
|
</a>
|
||||||
<nav className={styles.nav}>
|
<nav className={styles.nav}>
|
||||||
<ul className={styles.navUl}>
|
<ul className={styles.navUl}>{this.renderLinks()}</ul>
|
||||||
{this.renderLinks()}
|
|
||||||
</ul>
|
|
||||||
</nav>
|
</nav>
|
||||||
<a
|
<a
|
||||||
href=""
|
href=""
|
||||||
@ -172,16 +171,10 @@ GlobalPagination.defaultProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
GlobalPagination.propTypes = {
|
GlobalPagination.propTypes = {
|
||||||
count: PropTypes.oneOfType([
|
count: PropTypes.oneOfType([PropTypes.number, PropTypes.bool]),
|
||||||
PropTypes.number,
|
|
||||||
PropTypes.bool,
|
|
||||||
]),
|
|
||||||
onChangeParams: PropTypes.func,
|
onChangeParams: PropTypes.func,
|
||||||
params: PropTypes.shape({
|
params: PropTypes.shape({
|
||||||
_page: PropTypes.oneOfType([
|
_page: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
PropTypes.string,
|
|
||||||
PropTypes.number,
|
|
||||||
]),
|
|
||||||
_limit: PropTypes.number,
|
_limit: PropTypes.number,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
@ -46,8 +46,8 @@
|
|||||||
"configurable": false,
|
"configurable": false,
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
"public_id": {
|
"provider_metadata": {
|
||||||
"type": "string",
|
"type": "json",
|
||||||
"configurable": false
|
"configurable": false
|
||||||
},
|
},
|
||||||
"related": {
|
"related": {
|
||||||
|
|||||||
@ -42,18 +42,23 @@ module.exports = {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
file.public_id = image.public_id;
|
|
||||||
file.url = image.secure_url;
|
file.url = image.secure_url;
|
||||||
|
file.provider_metadata = {
|
||||||
|
public_id: image.public_id,
|
||||||
|
resource_type: image.resource_type,
|
||||||
|
};
|
||||||
resolve();
|
resolve();
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
intoStream(file.buffer).pipe(upload_stream);
|
intoStream(file.buffer).pipe(upload_stream);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async delete(file) {
|
async delete(file) {
|
||||||
try {
|
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,
|
invalidate: true,
|
||||||
|
resource_type: resource_type || 'image',
|
||||||
});
|
});
|
||||||
if (response.result !== 'ok') {
|
if (response.result !== 'ok') {
|
||||||
throw {
|
throw {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user