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,11 +550,47 @@ var global = self, ...@@ -513,11 +550,47 @@ 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;
if (is_excluded_url(url)) {
queue = fetch(event.request);
} else {
mapped_url = get_mapped_url(url);
if (self.jio_cache.development_mode && mapped_url) {
queue = fetch(mapped_url)
.then(undefined, function (error) {
if (error.status_code === 404) {
console.log(url + ',' + specific_url + ' not found by ' + mapped_url + ' storage');
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');
return get_from_cache_storage(url);
} else {
throw error;
}
})
.then(function (response) {
if (response.ok) {
save_in_dev_storage(url, response.clone());
//console.log('returned: ' + url);
return response;
} else {
debugger;
}
})
.then(undefined, function (error) {
console.log(error);
});
} else {
queue = Promise.resolve() queue = Promise.resolve()
.then(function () { .then(function () {
if (self.jio_cache.development_mode) { if (self.jio_cache.development_mode) {
...@@ -569,6 +642,8 @@ var global = self, ...@@ -569,6 +642,8 @@ var global = self,
.then(undefined, function (error) { .then(undefined, function (error) {
console.log(error); console.log(error);
}); });
}
}
event.respondWith(queue); event.respondWith(queue);
}; };
......
...@@ -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