Commit 55c92d32 authored by Boris Kocherov's avatar Boris Kocherov Committed by Boris Kocherov

erp5_officejs: add excluded and mapped paths in serviceworker

parent 1078028d
......@@ -121,6 +121,8 @@ var global = self,
'Web Style': 'text/css'
},
map_url2id_prefix = {},
map_url2url = {},
exclude_urls = [],
map_content_type2portal_type = {},
websections_url = [],
query_portal_types = "",
......@@ -138,6 +140,34 @@ var global = self,
}
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) {
var prefix,
relative_url,
......@@ -388,6 +418,13 @@ var global = self,
map_url2id_prefix[site_url] = '';
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 () {
var url;
for (url in map_url2id_prefix) {
......@@ -513,11 +550,47 @@ var global = self,
self.jio_cache_fetch = function (event) {
var url = event.request.url,
mapped_url,
relative_url = get_relative_url(url),
specific_url = get_specific_url(url) || relative_url,
not_found_in_dev_storage = false,
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()
.then(function () {
if (self.jio_cache.development_mode) {
......@@ -569,6 +642,8 @@ var global = self,
.then(undefined, function (error) {
console.log(error);
});
}
}
event.respondWith(queue);
};
......
......@@ -87,6 +87,25 @@
<key> <string>language</string> </key>
<value> <string>en</string> </value>
</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>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
......@@ -230,7 +249,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>952.23052.23734.23330</string> </value>
<value> <string>953.19783.2282.55313</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +267,7 @@
</tuple>
<state>
<tuple>
<float>1467787144.88</float>
<float>1471734262.06</float>
<string>UTC</string>
</tuple>
</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