Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function checkValidServiceWorker (swUrl) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl)
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
if (
response.status === 404 ||
response.headers.get('content-type').indexOf('javascript') === -1
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload()
})
})
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl)
}
}).then(({ data }) => {
cloudinary = data.cloudinaryRequest;
const body = new FormData();
body.append('api_key', cloudinary.apiKey);
body.append('signature', cloudinary.signature);
body.append('timestamp', cloudinary.timestamp);
[].slice.call(files).forEach(file => body.attach('file', file));
return fetch(cloudinary.url, {
method: 'POST',
body,
});
}).then(({ body }) => {
body.id = body.public_id;
.then(({ data }) => {
cloudinary = data.cloudinaryRequest;
const body = new FormData();
body.append('api_key', cloudinary.apiKey);
body.append('signature', cloudinary.signature);
body.append('timestamp', cloudinary.timestamp);
[].slice.call(files).forEach(file => body.attach('file', file));
return fetch(cloudinary.url, {
method: 'POST',
body,
});
})
.then(({ body }) => {