Commit e594e132 authored by Roque's avatar Roque

erp5_officejs: switch bootloader from appcache to precache script

- new storage to handle precache manifests instead of appcache
parent 5d2a6b37
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<script src="${latest_version}/rsvp.js"></script> <script src="${latest_version}/rsvp.js"></script>
<script src="${latest_version}/renderjs.js"></script> <script src="${latest_version}/renderjs.js"></script>
<script src="${latest_version}/jiodev.js"></script> <script src="${latest_version}/jiodev.js"></script>
<script src="jio_appcachestorage.js"></script> <script src="jio_precachestorage.js"></script>
<script src="gadget_officejs_bootloader.js"></script> <script src="gadget_officejs_bootloader.js"></script>
</head> </head>
......
...@@ -159,11 +159,13 @@ ...@@ -159,11 +159,13 @@
</record> </record>
<record id="3" aka="AAAAAAAAAAM="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -207,16 +209,20 @@ ...@@ -207,16 +209,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -239,7 +245,7 @@ ...@@ -239,7 +245,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>967.13437.59295.35805</string> </value> <value> <string>983.5704.62351.904</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -257,7 +263,7 @@ ...@@ -257,7 +263,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1525098912.16</float> <float>1587737022.07</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
...@@ -266,16 +272,20 @@ ...@@ -266,16 +272,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="5" aka="AAAAAAAAAAU="> <record id="5" aka="AAAAAAAAAAU=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -323,7 +333,9 @@ ...@@ -323,7 +333,9 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
...@@ -36,7 +36,7 @@ var repair = false; ...@@ -36,7 +36,7 @@ var repair = false;
} }
}, },
remote_sub_storage: { remote_sub_storage: {
type: "appcache", type: "precache",
manifest: gadget.props.cache_file, manifest: gadget.props.cache_file,
version: gadget.props.version_url, version: gadget.props.version_url,
take_installer: true take_installer: true
......
...@@ -154,11 +154,13 @@ ...@@ -154,11 +154,13 @@
</record> </record>
<record id="3" aka="AAAAAAAAAAM="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -202,16 +204,20 @@ ...@@ -202,16 +204,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -234,7 +240,7 @@ ...@@ -234,7 +240,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>967.24634.17714.15001</string> </value> <value> <string>983.27330.42899.26726</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +258,7 @@ ...@@ -252,7 +258,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1543506463.01</float> <float>1587734784.31</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
...@@ -261,16 +267,20 @@ ...@@ -261,16 +267,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="5" aka="AAAAAAAAAAU="> <record id="5" aka="AAAAAAAAAAU=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -318,7 +328,9 @@ ...@@ -318,7 +328,9 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
/*jslint indent:2, maxlen: 80, nomen: true */
/*global jIO, RSVP, window, Rusha, Blob, URL, console */
(function (window, jIO, RSVP, Rusha, Blob, URL, console) {
"use strict";
var rusha = new Rusha();
function PreCacheStorage(spec) {
this._precache_manifest_script = spec.manifest;
this._take_installer = spec.take_installer || false;
this._origin_url = spec.origin_url !== undefined ?
spec.origin_url : window.location.href;
this._version = spec.version || "";
this._prefix = spec.prefix || "./";
this._documents = {};
// Harcoded here, find a better way.
if (this._take_installer) {
this._relative_url_list = [
this._prefix,
this._prefix + "gadget_officejs_bootloader.js",
this._prefix + "gadget_officejs_bootloader.html",
this._prefix + "gadget_officejs_bootloader_presentation.html",
this._prefix + "gadget_officejs_bootloader_presentation.js",
this._prefix + "gadget_officejs_bootloader_presentation.css",
this._prefix + "gadget_officejs_bootloader_serviceworker.js",
this._prefix + "gadget_erp5_nojqm.css",
this._prefix + "officejs_logo.png",
this._prefix + "jio_precachestorage.js"
];
} else {
this._relative_url_list = [this._prefix + "/"];
}
if (this._take_installer) {
this._version = 'app/';
}
this._version = this._prefix + this._version;
}
PreCacheStorage.prototype.get = function (id) {
if (this._documents.hasOwnProperty(id)) {
return this._documents[id];
}
throw new jIO.util.jIOError('can not find document : ' + id, 404);
};
PreCacheStorage.prototype.hasCapacity = function () {
return true;
};
PreCacheStorage.prototype.getAttachment = function (origin_url,
relative_url) {
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
type: "GET",
url: new URL(relative_url, origin_url),
dataType: "blob"
});
})
.push(function (result) {
return result.target.response;
});
};
PreCacheStorage.prototype.allAttachments = function (id) {
if (id === this._origin_url) {
var result = {}, i, len = this._relative_url_list.length;
for (i = 0; i < len; i += 1) {
result[this._relative_url_list[i]] = {};
}
return result;
}
return [];
};
PreCacheStorage.prototype.buildQuery = function () {
var result = [], id;
for (id in this._documents) {
if (this._documents.hasOwnProperty(id)) {
result.push({
'id': id,
'value': this._documents[id],
'doc': this._documents[id]
});
}
}
return result;
};
PreCacheStorage.prototype.repair = function () {
var storage = this, url;
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
type: "GET",
url: new URL(storage._precache_manifest_script,
new URL(storage._version, storage._origin_url))
});
})
.push(function (response) {
var base_manifest_text = response.target.responseText,
relative_url_list,
i,
hash = rusha.digestFromString(base_manifest_text +
response.target
.getResponseHeader("ETag"));
relative_url_list = Object.keys(JSON.parse(base_manifest_text));
storage._relative_url_list.push(storage._version);
storage._relative_url_list.push(storage._version +
storage._precache_manifest_script);
storage._documents[storage._origin_url] = {'hash': hash};
for (i = 0; i < relative_url_list.length; i += 1) {
url = relative_url_list[i];
if (url.includes('?')) {
throw new Error("It is not allow to cache urls with parameters." +
" url: " + url);
}
storage._relative_url_list.push(
storage._version + url
);
}
}, function (error) {
if (error.target.status === 404 && !error.message) {
error.message = "Couldn't get the precache manifest '" +
storage._precache_manifest_script + "'";
}
throw error;
});
};
jIO.addStorage('precache', PreCacheStorage);
}(window, jIO, RSVP, Rusha, Blob, URL, console));
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