Last active
November 30, 2023 17:58
-
-
Save r14c/a80b5589876c87392c0eed0a92ba82d6 to your computer and use it in GitHub Desktop.
Bulk Delete Storyblok Assets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bashEm(spaceId, token) { | |
return (ids) => fetch(`https://app.storyblok.com/v1_us/spaces/${spaceId}/assets/bulk_destroy`, { | |
"headers": { | |
"authorization": token, | |
"content-type": "application/json", | |
}, | |
"referrer": "https://app.storyblok.com/", | |
"body": JSON.stringify({ ids: ids }), | |
"method": "POST", | |
"mode": "cors", | |
"credentials": "include" | |
}) | |
} | |
Array.prototype.map.call(document.querySelectorAll('input[aria-label="Select Asset"]'), function (el) { | |
// parse asset ids | |
return parseInt(el.id.split('-').pop(), 10) | |
}).reduce((acc, curr, i) => { | |
// chunk the list into groups of 25 since the bulk_destory task doesn't process more than that at a time | |
const index = Math.floor(i / 25); | |
if (!acc[index]) { | |
acc[index] = []; | |
} | |
acc[index].push(curr); | |
return acc; | |
}, []).map(bashEm(SPACE_ID, STORYBLOK_TOKEN)); /* you can grab these from the network tab */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment