Commit 37b59a92 authored by Boris Kocherov's avatar Boris Kocherov

erp5_officejs: add excluded and mapped paths in serviceworker

parent 11cf0995
...@@ -121,6 +121,8 @@ var global = self, ...@@ -121,6 +121,8 @@ var global = self,
'Web Style': 'text/css' 'Web Style': 'text/css'
}, },
map_url2id_prefix = {}, map_url2id_prefix = {},
map_url2url = {},
exclude_urls = [],
map_content_type2portal_type = {}, map_content_type2portal_type = {},
websections_url = [], websections_url = [],
query_portal_types = "", query_portal_types = "",
...@@ -138,6 +140,34 @@ var global = self, ...@@ -138,6 +140,34 @@ var global = self,
} }
return 'text_content'; return 'text_content';
}, },
is_excluded_url = function (url) {
var prefix, i;
for (i = 0; i < exclude_urls.length; i++) {
prefix = exclude_urls[i];
if (url === prefix) {
return true;
}
if (url.startsWith(prefix + '/')) {
return true;
}
}
return false;
},
get_mapped_url = function (url) {
var prefix,
prefix_id,
key;
for (key in map_url2url) {
if (map_url2url.hasOwnProperty(key)) {
if (url === key) {
return map_url2url[key];
}
if (url.startsWith(key)) {
return url.replace(key, map_url2url[key]);
}
}
}
},
get_relative_url = function (url) { get_relative_url = function (url) {
var prefix, var prefix,
relative_url, relative_url,
...@@ -388,6 +418,13 @@ var global = self, ...@@ -388,6 +418,13 @@ var global = self,
map_url2id_prefix[site_url] = ''; map_url2id_prefix[site_url] = '';
map_url2id_prefix['https:'] = ''; map_url2id_prefix['https:'] = '';
exclude_urls.push(site_url + 'hateoas');
exclude_urls.push(site_url + 'hateoasnoauth');
map_url2url[site_url + 'rjsunsafe/ooffice/apps/'] = 'https://localhost/OfficeWebDeploy/apps/';
map_url2url[site_url + 'rjsunsafe/ooffice/sdkjs/'] = 'https://localhost/OfficeWebDeploy/sdkjs/';
map_url2url[site_url + 'rjsunsafe/ooffice/vendor/'] = 'https://localhost/OfficeWebDeploy/vendor/';
(function () { (function () {
var url; var url;
for (url in map_url2id_prefix) { for (url in map_url2id_prefix) {
...@@ -513,62 +550,100 @@ var global = self, ...@@ -513,62 +550,100 @@ var global = self,
self.jio_cache_fetch = function (event) { self.jio_cache_fetch = function (event) {
var url = event.request.url, var url = event.request.url,
mapped_url,
relative_url = get_relative_url(url), relative_url = get_relative_url(url),
specific_url = get_specific_url(url) || relative_url, specific_url = get_specific_url(url) || relative_url,
not_found_in_dev_storage = false, not_found_in_dev_storage = false,
queue; queue;
queue = Promise.resolve() if (is_excluded_url(url)) {
.then(function () { queue = fetch(event.request);
if (self.jio_cache.development_mode) { } else {
// 1 level storage development mapped_url = get_mapped_url(url);
return get_from_storage(url, self.jio_dev_storage); if (self.jio_cache.development_mode && mapped_url) {
} else { queue = fetch(mapped_url)
throw {status_code: 404}; .then(undefined, function (error) {
} if (error.status_code === 404) {
}) console.log(url + ',' + specific_url + ' not found by ' + mapped_url + ' storage');
.then(undefined, function (error) { return get_from_storage(url, self.jio_erp5_cache_storage);
if (error.status_code === 404) { } else {
if (self.jio_cache.development_mode) { throw error;
console.log(url + ',' + specific_url + ' not found in dev storage'); }
not_found_in_dev_storage = true; })
} .then(undefined, function (error) {
// 2 level storage from erp5 if (error.status_code === 404) {
return get_from_storage(url, self.jio_erp5_cache_storage); console.log(url + ',' + specific_url + ' not found in erp5 cache storage');
} else { return get_from_cache_storage(url);
throw error; } else {
} throw error;
}) }
.then(undefined, function (error) { })
if (error.status_code === 404) { .then(function (response) {
console.log(url + ',' + specific_url + ' not found in erp5 cache storage'); if (response.ok) {
// 3 level cache urls one for all aplications save_in_dev_storage(url, response.clone());
return get_from_cache_storage(url); //console.log('returned: ' + url);
} else { return response;
throw error; } else {
} debugger;
}) }
.then(undefined, function (error) { })
if (error.status_code === 404) { .then(undefined, function (error) {
console.log(url + ',' + relative_url + ' not found in cache storage'); console.log(error);
// fetch });
return fetch(event.request); } else {
} else { queue = Promise.resolve()
throw error; .then(function () {
} if (self.jio_cache.development_mode) {
}) // 1 level storage development
.then(function (response) { return get_from_storage(url, self.jio_dev_storage);
if (response.ok) { } else {
if (not_found_in_dev_storage) { throw {status_code: 404};
save_in_dev_storage(url, response.clone()); }
} })
//console.log('returned: ' + url); .then(undefined, function (error) {
return response; if (error.status_code === 404) {
} if (self.jio_cache.development_mode) {
}) console.log(url + ',' + specific_url + ' not found in dev storage');
.then(undefined, function (error) { not_found_in_dev_storage = true;
console.log(error); }
}); // 2 level storage from erp5
return get_from_storage(url, self.jio_erp5_cache_storage);
} else {
throw error;
}
})
.then(undefined, function (error) {
if (error.status_code === 404) {
console.log(url + ',' + specific_url + ' not found in erp5 cache storage');
// 3 level cache urls one for all aplications
return get_from_cache_storage(url);
} else {
throw error;
}
})
.then(undefined, function (error) {
if (error.status_code === 404) {
console.log(url + ',' + relative_url + ' not found in cache storage');
// fetch
return fetch(event.request);
} else {
throw error;
}
})
.then(function (response) {
if (response.ok) {
if (not_found_in_dev_storage) {
save_in_dev_storage(url, response.clone());
}
//console.log('returned: ' + url);
return response;
}
})
.then(undefined, function (error) {
console.log(error);
});
}
}
event.respondWith(queue); event.respondWith(queue);
}; };
...@@ -583,4 +658,4 @@ var global = self, ...@@ -583,4 +658,4 @@ var global = self,
self.addEventListener('fetch', self.jio_cache_fetch); self.addEventListener('fetch', self.jio_cache_fetch);
self.addEventListener("activate", self.jio_cache_activate); self.addEventListener("activate", self.jio_cache_activate);
}(self, fetch)); }(self, fetch));
\ No newline at end of file
...@@ -87,6 +87,25 @@ ...@@ -87,6 +87,25 @@
<key> <string>language</string> </key> <key> <string>language</string> </key>
<value> <string>en</string> </value> <value> <string>en</string> </value>
</item> </item>
<item>
<key> <string>modification_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1469184627.3</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item> <item>
<key> <string>portal_type</string> </key> <key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value> <value> <string>Web Script</string> </value>
...@@ -230,7 +249,7 @@ ...@@ -230,7 +249,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>952.23052.23734.23330</string> </value> <value> <string>953.19783.2282.55313</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +267,7 @@ ...@@ -248,7 +267,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1467787144.88</float> <float>1471734262.06</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment