From 305a620aed181302907dca884aa69caf12769ed2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 28 Nov 2017 15:41:41 +0900 Subject: [PATCH] :v: --- src/web/app/boot.js | 7 +++++++ src/web/app/sw.js | 6 ++++++ src/web/assets/help.js | 8 ++++++++ src/web/server.ts | 1 + 4 files changed, 22 insertions(+) create mode 100644 src/web/assets/help.js diff --git a/src/web/app/boot.js b/src/web/app/boot.js index a5f0e04d31..0a3154ad88 100644 --- a/src/web/app/boot.js +++ b/src/web/app/boot.js @@ -92,6 +92,13 @@ '\n\n' + 'New version of Misskey available. The page will be reloaded.'); + // Clear cache (serive worker) + try { + navigator.serviceWorker.controller.postMessage('clear'); + } catch (e) { + console.error(e); + } + // Force reload location.reload(true); } diff --git a/src/web/app/sw.js b/src/web/app/sw.js index 2074ee39c4..669703b16c 100644 --- a/src/web/app/sw.js +++ b/src/web/app/sw.js @@ -63,3 +63,9 @@ self.addEventListener('push', ev => { }); })); }); + +self.addEventListener('message', ev => { + if (ev.data == 'clear') { + caches.keys().then(keys => keys.forEach(key => caches.delete(key))); + } +}); diff --git a/src/web/assets/help.js b/src/web/assets/help.js new file mode 100644 index 0000000000..475c506789 --- /dev/null +++ b/src/web/assets/help.js @@ -0,0 +1,8 @@ +const yn = window.confirm( + 'サーバー上に存在しないスクリプトがリクエストされました。お使いのMisskeyのバージョンが古いことが原因の可能性があります。Misskeyを更新しますか?'); + +if (yn) { + location.reload(true); +} else { + alert('問題が解決しない場合はサーバー管理者までお問い合せください。'); +} diff --git a/src/web/server.ts b/src/web/server.ts index e368d3e62d..791b75ce09 100644 --- a/src/web/server.ts +++ b/src/web/server.ts @@ -39,6 +39,7 @@ app.get('/apple-touch-icon.png', (req, res) => res.sendFile(`${__dirname}/assets app.use('/assets', express.static(`${__dirname}/assets`, { maxAge: ms('7 days') })); +app.use('/assets/*.js', (req, res) => res.sendFile(`${__dirname}/assets/help.js`)); app.use('/assets', (req, res) => { res.sendStatus(404); });