diff options
author | Andrew Dolgov <[email protected]> | 2017-06-28 12:32:48 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2017-06-28 12:32:48 +0300 |
commit | 9f4927825bb5efeefdff9a2aac05c5b3200f5ef6 (patch) | |
tree | f7782cb57127c68bfd5c67fb0d90c725eb8f0e68 /worker.js | |
parent | 4496d4a5e1f3ddb5fd0b3a0315f12c207e7c9041 (diff) |
move to internal user management because it's impossible to implement
proper transparent offline mode with http auth (worker is incapable of
authenticating properly)
MIGRATION:
1. disable HTTP authentication (this is important!)
2. add two new tables to db/scratch.db (sessions & users)
3. create users via useradm.php (same names and passwords, previous data
is kept)
Diffstat (limited to 'worker.js')
-rw-r--r-- | worker.js | 42 |
1 files changed, 28 insertions, 14 deletions
@@ -44,7 +44,7 @@ self.addEventListener('message', function(event){ cache.keys().then(function(keys) { for (var i = 0; i < keys.length; i++) { - fetch(keys[i],{credentials:'same-origin'}).then(function(resp) { + fetch(keys[i]).then(function(resp) { if (resp.status == 200) { cache.put(resp.url, resp); } @@ -59,24 +59,38 @@ self.addEventListener('message', function(event){ this.addEventListener('fetch', function(event) { var req = event.request.clone(); - if (!navigator.onLine) { - event.respondWith( - caches.match(req).then(function(resp) { + event.respondWith( + caches.match(req).then(function(resp) { - if (resp) return resp; + if (resp) { + return resp; + } - if (req.url.match("read.html")) { - return caches.match("read.html"); - } + if (req.url.match("read.html")) { + return caches.match("read.html"); + } - if (req.url.match("offline.html")) { - return caches.match("offline.html"); + if (req.url.match("offline.html")) { + return caches.match("offline.html"); + } + + return fetch(req).then(function(resp) { + + if (resp.status == 200) { + if (resp.url.match("backend.php\\?op=cover")) { + return caches.open(CACHE_NAME).then(function(cache) { + cache.put(resp.url, resp.clone()); + return resp; + }); + } } - if (req.url.match("index.php")) { + return resp; + }).catch(function() { + if (req.url[req.url.length-1] == "/" || req.url.match("index.php")) { return caches.match("offline.html"); } - }) - ); - } + }); + }) + ); }); |