orderiom-api-package
Advanced tools
Comparing version 0.4.77 to 0.4.78
{ | ||
"name": "orderiom-api-package", | ||
"version": "0.4.77", | ||
"version": "0.4.78", | ||
"description": "This package will install all necessary API calls for every orderiom restaurant", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -104,2 +104,35 @@ import { commonErrorCallback, restaurantIdEnv, $http } from '../common'; | ||
}, | ||
// Delete older caches of index.html file manually because workbox can't do it properly | ||
async deleteOlderIndexCaches() { | ||
// get all the cache storages for this website | ||
return caches.keys().then(res => { | ||
if(!res.length) return; | ||
// get the first cache storages for this website | ||
return caches.open(res[0]).then(cache => { | ||
// get all the cached requests | ||
return cache.keys().then(requests => { | ||
// get all the cached requests that is related to index.html | ||
const indexCaches = requests.filter(request => request.url.includes('index.html')) | ||
// If there is only one cached request for index.html then no need to do anything | ||
if(indexCaches.length <= 1) return; | ||
return Promise.all(indexCaches.map(async indexCache => { | ||
// Get the last modified time for all cache requests of index.html | ||
return cache.match(indexCache).then(response => { | ||
if(!response) return; | ||
indexCache.lastModified = new Date(response.headers.get('Last-Modified')).getTime() | ||
}) | ||
})).then(() => { | ||
// Delete the older caches of index.html | ||
indexCaches.sort((a, b) => b.lastModified - a.lastModified) | ||
const olderIndexCaches = indexCaches.slice(1, indexCaches.length) | ||
return Promise.all(olderIndexCaches.map(olderIndexCache => { | ||
return cache.delete(olderIndexCache); | ||
})) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}, | ||
contact({ }, data) { | ||
@@ -106,0 +139,0 @@ return $http.post('api/contact', data).then((res) => { |
129392
3231