underpost 3.2.5 → 3.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release.cd.yml +1 -2
- package/CHANGELOG.md +251 -1
- package/CLI-HELP.md +26 -13
- package/Dockerfile +0 -4
- package/README.md +3 -3
- package/bin/build.js +13 -3
- package/bin/deploy.js +570 -1
- package/bin/file.js +5 -0
- package/conf.js +11 -2
- package/jsconfig.json +1 -1
- package/manifests/cronjobs/dd-cron/dd-cron-backup.yaml +1 -1
- package/manifests/cronjobs/dd-cron/dd-cron-dns.yaml +1 -1
- package/manifests/deployment/dd-default-development/deployment.yaml +2 -6
- package/manifests/deployment/dd-test-development/deployment.yaml +136 -66
- package/manifests/deployment/dd-test-development/proxy.yaml +41 -5
- package/package.json +20 -11
- package/src/api/core/core.controller.js +10 -10
- package/src/api/core/core.service.js +10 -10
- package/src/api/default/default.controller.js +10 -10
- package/src/api/default/default.service.js +10 -10
- package/src/api/document/document.controller.js +12 -12
- package/src/api/document/document.model.js +10 -16
- package/src/api/file/file.controller.js +8 -8
- package/src/api/file/file.model.js +10 -10
- package/src/api/file/file.service.js +36 -36
- package/src/api/test/test.controller.js +8 -8
- package/src/api/test/test.service.js +8 -8
- package/src/api/user/guest.service.js +99 -0
- package/src/api/user/user.controller.js +6 -6
- package/src/api/user/user.model.js +8 -13
- package/src/api/user/user.service.js +3 -20
- package/src/cli/deploy.js +33 -30
- package/src/cli/fs.js +62 -5
- package/src/cli/image.js +43 -1
- package/src/cli/index.js +5 -1
- package/src/cli/release.js +57 -1
- package/src/cli/repository.js +35 -3
- package/src/cli/run.js +300 -35
- package/src/cli/ssh.js +1 -1
- package/src/cli/static.js +43 -115
- package/src/client/Default.index.js +21 -33
- package/src/client/components/core/404.js +4 -4
- package/src/client/components/core/500.js +4 -4
- package/src/client/components/core/Account.js +73 -60
- package/src/client/components/core/AgGrid.js +23 -33
- package/src/client/components/core/Alert.js +12 -13
- package/src/client/components/core/AppStore.js +1 -1
- package/src/client/components/core/Auth.js +20 -32
- package/src/client/components/core/Badge.js +7 -13
- package/src/client/components/core/BtnIcon.js +15 -17
- package/src/client/components/core/CalendarCore.js +42 -63
- package/src/client/components/core/Chat.js +13 -15
- package/src/client/components/core/ClientEvents.js +87 -0
- package/src/client/components/core/ColorPaletteElement.js +309 -0
- package/src/client/components/core/Content.js +17 -14
- package/src/client/components/core/Css.js +15 -71
- package/src/client/components/core/CssCore.js +12 -16
- package/src/client/components/core/D3Chart.js +4 -4
- package/src/client/components/core/Docs.js +60 -59
- package/src/client/components/core/DropDown.js +69 -91
- package/src/client/components/core/EventBus.js +92 -0
- package/src/client/components/core/EventsUI.js +14 -17
- package/src/client/components/core/FileExplorer.js +102 -234
- package/src/client/components/core/FullScreen.js +47 -75
- package/src/client/components/core/Input.js +24 -69
- package/src/client/components/core/Keyboard.js +25 -18
- package/src/client/components/core/KeyboardAvoidance.js +145 -0
- package/src/client/components/core/LoadingAnimation.js +25 -31
- package/src/client/components/core/LogIn.js +41 -41
- package/src/client/components/core/LogOut.js +23 -14
- package/src/client/components/core/Modal.js +397 -176
- package/src/client/components/core/NotificationManager.js +14 -18
- package/src/client/components/core/Panel.js +54 -50
- package/src/client/components/core/PanelForm.js +25 -125
- package/src/client/components/core/Polyhedron.js +110 -214
- package/src/client/components/core/PublicProfile.js +39 -32
- package/src/client/components/core/Recover.js +52 -48
- package/src/client/components/core/Responsive.js +88 -32
- package/src/client/components/core/RichText.js +9 -18
- package/src/client/components/core/Router.js +24 -3
- package/src/client/components/core/SearchBox.js +37 -37
- package/src/client/components/core/SignUp.js +39 -30
- package/src/client/components/core/SocketIo.js +31 -2
- package/src/client/components/core/SocketIoHandler.js +6 -6
- package/src/client/components/core/ToggleSwitch.js +8 -20
- package/src/client/components/core/ToolTip.js +5 -17
- package/src/client/components/core/Translate.js +56 -59
- package/src/client/components/core/Validator.js +26 -16
- package/src/client/components/core/Wallet.js +15 -26
- package/src/client/components/core/Worker.js +140 -25
- package/src/client/components/core/windowGetDimensions.js +7 -7
- package/src/client/components/default/{MenuDefault.js → AppShellDefault.js} +87 -87
- package/src/client/components/default/CssDefault.js +12 -12
- package/src/client/components/default/LogInDefault.js +6 -4
- package/src/client/components/default/LogOutDefault.js +6 -4
- package/src/client/components/default/RouterDefault.js +47 -0
- package/src/client/components/default/SettingsDefault.js +4 -4
- package/src/client/components/default/SignUpDefault.js +6 -4
- package/src/client/components/default/TranslateDefault.js +3 -3
- package/src/client/services/core/core.service.js +17 -49
- package/src/client/services/default/default.management.js +139 -242
- package/src/client/services/default/default.service.js +10 -16
- package/src/client/services/document/document.service.js +14 -19
- package/src/client/services/file/file.service.js +8 -13
- package/src/client/services/test/test.service.js +8 -13
- package/src/client/services/user/guest.service.js +79 -0
- package/src/client/services/user/user.management.js +5 -5
- package/src/client/services/user/user.service.js +14 -20
- package/src/client/ssr/body/404.js +3 -3
- package/src/client/ssr/body/500.js +3 -3
- package/src/client/ssr/body/CacheControl.js +5 -2
- package/src/client/ssr/body/DefaultSplashScreen.js +19 -12
- package/src/client/ssr/mailer/DefaultRecoverEmail.js +19 -20
- package/src/client/ssr/mailer/DefaultVerifyEmail.js +15 -16
- package/src/client/ssr/offline/Maintenance.js +12 -11
- package/src/client/ssr/offline/NoNetworkConnection.js +3 -3
- package/src/client/ssr/pages/Test.js +2 -2
- package/src/client/sw/core.sw.js +212 -0
- package/src/index.js +1 -1
- package/src/runtime/express/Dockerfile +4 -4
- package/src/runtime/lampp/Dockerfile +8 -7
- package/src/runtime/wp/Dockerfile +11 -17
- package/src/server/client-build-docs.js +45 -46
- package/src/server/client-build.js +334 -60
- package/src/server/client-formatted.js +47 -16
- package/src/server/conf.js +5 -4
- package/src/server/ipfs-client.js +232 -91
- package/src/server/process.js +13 -27
- package/src/server/start.js +6 -3
- package/src/server/valkey.js +134 -235
- package/tsconfig.docs.json +15 -0
- package/typedoc.json +20 -0
- package/jsdoc.json +0 -52
- package/src/client/components/core/ColorPalette.js +0 -5267
- package/src/client/components/core/JoyStick.js +0 -80
- package/src/client/components/default/RoutesDefault.js +0 -49
- package/src/client/sw/default.sw.js +0 -127
- package/src/client/sw/template.sw.js +0 -84
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import JoystickController from 'joystick-controller';
|
|
2
|
-
import { getDirection, getId } from './CommonJs.js';
|
|
3
|
-
import { append, s } from './VanillaJs.js';
|
|
4
|
-
import { getProxyPath } from './Router.js';
|
|
5
|
-
|
|
6
|
-
const logger = loggerFactory(import.meta);
|
|
7
|
-
|
|
8
|
-
const JoyStick = {
|
|
9
|
-
Tokens: {},
|
|
10
|
-
Render: async function (options = { id: '', callback: ({ joyDataSet }) => {}, callBackTime: 50 }) {
|
|
11
|
-
const { callback, callBackTime } = options;
|
|
12
|
-
const id = options.id ? options.id : getId(this.Tokens, 'joystick-');
|
|
13
|
-
this.Tokens[id] = { callback };
|
|
14
|
-
append(
|
|
15
|
-
'body',
|
|
16
|
-
html`
|
|
17
|
-
<style>
|
|
18
|
-
.dynamic-joystick-container-${id} {
|
|
19
|
-
/* border: 2px solid red; */
|
|
20
|
-
left: 5px;
|
|
21
|
-
bottom: 5px;
|
|
22
|
-
height: 175px;
|
|
23
|
-
width: 175px;
|
|
24
|
-
z-index: 3;
|
|
25
|
-
}
|
|
26
|
-
.joy-img-background-${id} {
|
|
27
|
-
width: 50%;
|
|
28
|
-
height: 50%;
|
|
29
|
-
opacity: 0.8;
|
|
30
|
-
transition: 0.1;
|
|
31
|
-
}
|
|
32
|
-
.dynamic-joystick-container-${id}:hover {
|
|
33
|
-
}
|
|
34
|
-
.joy-img-background-${id}:hover {
|
|
35
|
-
width: 54%;
|
|
36
|
-
height: 54%;
|
|
37
|
-
opacity: 1;
|
|
38
|
-
}
|
|
39
|
-
</style>
|
|
40
|
-
<div class="abs dynamic-joystick-container-${id}">
|
|
41
|
-
<img class="abs center joy-img-background-${id}" src="${getProxyPath()}assets/joy/joy_alpha.png" />
|
|
42
|
-
</div>
|
|
43
|
-
`,
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
this.Tokens[id].instance = new JoystickController(
|
|
47
|
-
{
|
|
48
|
-
maxRange: 70,
|
|
49
|
-
level: 10,
|
|
50
|
-
radius: 70,
|
|
51
|
-
joystickRadius: 50,
|
|
52
|
-
opacity: 0.5,
|
|
53
|
-
// containerClass: 'joystick-container',
|
|
54
|
-
// controllerClass: 'joystick-controller',
|
|
55
|
-
// joystickClass: 'joystick',
|
|
56
|
-
distortion: true,
|
|
57
|
-
dynamicPosition: true,
|
|
58
|
-
dynamicPositionTarget: s(`.dynamic-joystick-container-${id}`),
|
|
59
|
-
mouseClickButton: 'ALL',
|
|
60
|
-
hideContextMenu: true,
|
|
61
|
-
// x: '120px',
|
|
62
|
-
// y: '120px',
|
|
63
|
-
},
|
|
64
|
-
(args = { x, y, leveledX, leveledY, distance, angle }) => {
|
|
65
|
-
const { angle } = args;
|
|
66
|
-
if (angle === 0) return (this.Tokens[id].joyDataSet = undefined);
|
|
67
|
-
const radians = parseFloat(angle);
|
|
68
|
-
const direction = getDirection({ radians });
|
|
69
|
-
this.Tokens[id].joyDataSet = { ...args, radians, direction };
|
|
70
|
-
// logger.info(this.Tokens[id].joyDataSet, id);
|
|
71
|
-
},
|
|
72
|
-
);
|
|
73
|
-
setInterval(() => {
|
|
74
|
-
if (!this.Tokens[id].joyDataSet || !this.Tokens[id].joyDataSet.direction) return;
|
|
75
|
-
this.Tokens[id].callback({ joyDataSet: this.Tokens[id].joyDataSet });
|
|
76
|
-
}, callBackTime);
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export { JoyStick };
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { loggerFactory } from '../core/Logger.js';
|
|
2
|
-
import { Modal } from '../core/Modal.js';
|
|
3
|
-
import { s } from '../core/VanillaJs.js';
|
|
4
|
-
import { getProxyPath } from '../core/Router.js';
|
|
5
|
-
|
|
6
|
-
const logger = loggerFactory(import.meta);
|
|
7
|
-
|
|
8
|
-
const BannerAppTemplate = html`<strong class="inl" style="font-family: system-ui">PWA</strong>`;
|
|
9
|
-
|
|
10
|
-
// Router
|
|
11
|
-
const RoutesDefault = () => {
|
|
12
|
-
return {
|
|
13
|
-
'/': {
|
|
14
|
-
title: 'Home',
|
|
15
|
-
render: () => Modal.onHomeRouterEvent(),
|
|
16
|
-
},
|
|
17
|
-
'/home': { title: 'home', render: () => Modal.onHomeRouterEvent() },
|
|
18
|
-
'/settings': { title: 'settings', render: () => s(`.main-btn-settings`).click() },
|
|
19
|
-
'/log-in': { title: 'log-in', render: () => s(`.main-btn-log-in`).click() },
|
|
20
|
-
'/sign-up': { title: 'sign-up', render: () => s(`.main-btn-sign-up`).click() },
|
|
21
|
-
'/log-out': {
|
|
22
|
-
title: 'log-out',
|
|
23
|
-
render: () => s(`.main-btn-log-out`).click(),
|
|
24
|
-
},
|
|
25
|
-
'/account': {
|
|
26
|
-
title: 'account',
|
|
27
|
-
render: () => s(`.main-btn-account`).click(),
|
|
28
|
-
},
|
|
29
|
-
'/docs': { title: 'docs', render: () => s(`.main-btn-docs`).click() },
|
|
30
|
-
'/chat': { title: 'docs', render: () => s(`.main-btn-chat`).click() },
|
|
31
|
-
'/blog': { title: 'docs', render: () => s(`.main-btn-blog`).click() },
|
|
32
|
-
'/recover': { title: 'recover', render: () => s(`.main-btn-recover`).click() },
|
|
33
|
-
'/default-management': {
|
|
34
|
-
title: 'default-management',
|
|
35
|
-
render: () => s(`.main-btn-default-management`).click(),
|
|
36
|
-
},
|
|
37
|
-
'/u': { title: 'public-profile', render: () => s(`.main-btn-public-profile`).click() },
|
|
38
|
-
'/404': { title: '404 Not Found', render: () => s(`.main-btn-404`).click() },
|
|
39
|
-
'/500': { title: '500 Server Error', render: () => s(`.main-btn-500`).click() },
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
window.Routes = RoutesDefault;
|
|
44
|
-
|
|
45
|
-
const RouterDefault = () => {
|
|
46
|
-
return { Routes: RoutesDefault };
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export { RoutesDefault, RouterDefault, BannerAppTemplate };
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This module provides a configurable Progressive Web App (PWA) service worker and caching strategies.
|
|
3
|
-
* It supports precaching assets, runtime caching with stale-while-revalidate strategy,
|
|
4
|
-
* and offline fallback handling.
|
|
5
|
-
* @module src/client/sw/default.sw.js
|
|
6
|
-
* @namespace PwaServiceWorker
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const PRE_CACHED_RESOURCES = self.renderPayload?.PRE_CACHED_RESOURCES ? self.renderPayload.PRE_CACHED_RESOURCES : [];
|
|
10
|
-
const CACHE_NAME = self.renderPayload?.CACHE_NAME ? self.renderPayload.CACHE_NAME : 'app-cache';
|
|
11
|
-
const PROXY_PATH = self.renderPayload?.PROXY_PATH ? self.renderPayload.PROXY_PATH : '/';
|
|
12
|
-
self.addEventListener('install', (event) => {
|
|
13
|
-
// Activate right away
|
|
14
|
-
self.skipWaiting();
|
|
15
|
-
|
|
16
|
-
event.waitUntil(
|
|
17
|
-
(async () => {
|
|
18
|
-
// Open the app's cache.
|
|
19
|
-
const cache = await caches.open(CACHE_NAME);
|
|
20
|
-
// Cache all static resources.
|
|
21
|
-
try {
|
|
22
|
-
await cache.addAll(PRE_CACHED_RESOURCES);
|
|
23
|
-
} catch (error) {
|
|
24
|
-
console.error(error);
|
|
25
|
-
}
|
|
26
|
-
// for (const cacheKey of PRE_CACHED_RESOURCES) {
|
|
27
|
-
// try {
|
|
28
|
-
// await cache.add(cacheKey);
|
|
29
|
-
// } catch (error) {
|
|
30
|
-
// console.error(error, cacheKey);
|
|
31
|
-
// }
|
|
32
|
-
// }
|
|
33
|
-
})(),
|
|
34
|
-
);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
self.addEventListener('activate', (event) => {
|
|
38
|
-
event.waitUntil(
|
|
39
|
-
(async () => {
|
|
40
|
-
// Enable navigation preload if it's supported.
|
|
41
|
-
// See https://developers.google.com/web/updates/2017/02/navigation-preload
|
|
42
|
-
if ('navigationPreload' in self.registration) {
|
|
43
|
-
await self.registration.navigationPreload.enable();
|
|
44
|
-
}
|
|
45
|
-
})(),
|
|
46
|
-
);
|
|
47
|
-
// Tell the active service worker to take control of the page immediately.
|
|
48
|
-
self.clients.claim();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
self.addEventListener('fetch', (event) => {
|
|
52
|
-
// Cache-First Strategy
|
|
53
|
-
event.respondWith(
|
|
54
|
-
(async () => {
|
|
55
|
-
// First, try to use the navigation preload response if it's supported.
|
|
56
|
-
try {
|
|
57
|
-
(async () => {
|
|
58
|
-
// Get the client.
|
|
59
|
-
if (event.request.url.match(location.origin)) {
|
|
60
|
-
const client = await clients.get(event.clientId);
|
|
61
|
-
if (client)
|
|
62
|
-
client.postMessage({
|
|
63
|
-
status: 'loader',
|
|
64
|
-
path: event.request.url.slice(location.origin.length),
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
})();
|
|
68
|
-
const preloadResponse = await event.preloadResponse;
|
|
69
|
-
if (preloadResponse) return preloadResponse;
|
|
70
|
-
return await fetch(event.request);
|
|
71
|
-
} catch (error) {
|
|
72
|
-
console.error('Fetch failed; returning offline page instead.', event.request.url, error);
|
|
73
|
-
// Fallback to the offline page.
|
|
74
|
-
const path = PRE_CACHED_RESOURCES.find((path) => event.request.url.match(path.replaceAll('/index.html', '')));
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
const cachedResponse = await caches.match(event.request);
|
|
78
|
-
if (cachedResponse) return cachedResponse;
|
|
79
|
-
const cache = await caches.open(CACHE_NAME);
|
|
80
|
-
const preCachedResponse = await cache.match(path);
|
|
81
|
-
if (!preCachedResponse) throw new Error(error.message);
|
|
82
|
-
return preCachedResponse;
|
|
83
|
-
} catch (error) {
|
|
84
|
-
console.error('Error opening cache for pre cached page', {
|
|
85
|
-
url: event.request.url,
|
|
86
|
-
error,
|
|
87
|
-
onLine: navigator.onLine,
|
|
88
|
-
});
|
|
89
|
-
try {
|
|
90
|
-
if (!navigator.onLine) {
|
|
91
|
-
if (event.request.method.toUpperCase() === 'GET') {
|
|
92
|
-
const cache = await caches.open(CACHE_NAME);
|
|
93
|
-
const preCachedResponse = await cache.match(
|
|
94
|
-
`${PROXY_PATH === '/' ? '' : PROXY_PATH}/offline/index.html`,
|
|
95
|
-
);
|
|
96
|
-
if (!preCachedResponse) throw new Error(error.message);
|
|
97
|
-
return preCachedResponse;
|
|
98
|
-
}
|
|
99
|
-
const response = new Response(JSON.stringify({ status: 'error', message: 'offline test response' }));
|
|
100
|
-
// response.status = 200;
|
|
101
|
-
response.headers.set('Content-Type', 'application/json');
|
|
102
|
-
return response;
|
|
103
|
-
}
|
|
104
|
-
if (event.request.method.toUpperCase() === 'GET') {
|
|
105
|
-
const cache = await caches.open(CACHE_NAME);
|
|
106
|
-
const preCachedResponse = await cache.match(
|
|
107
|
-
`${PROXY_PATH === '/' ? '' : PROXY_PATH}/maintenance/index.html`,
|
|
108
|
-
);
|
|
109
|
-
if (!preCachedResponse) throw new Error(error.message);
|
|
110
|
-
return preCachedResponse;
|
|
111
|
-
}
|
|
112
|
-
const response = new Response(JSON.stringify({ status: 'error', message: 'server in maintenance' }));
|
|
113
|
-
// response.status = 200;
|
|
114
|
-
response.headers.set('Content-Type', 'application/json');
|
|
115
|
-
return response;
|
|
116
|
-
} catch (error) {
|
|
117
|
-
console.error('Error opening cache for offline page', event.request.url, error);
|
|
118
|
-
const response = new Response(JSON.stringify({ status: 'error', message: error.message }));
|
|
119
|
-
// response.status = 200;
|
|
120
|
-
response.headers.set('Content-Type', 'application/json');
|
|
121
|
-
return response;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
})(),
|
|
126
|
-
);
|
|
127
|
-
});
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
// https://googlechrome.github.io/samples/service-worker/custom-offline-page/
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
Copyright 2015, 2019 Google Inc. All Rights Reserved.
|
|
5
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
you may not use this file except in compliance with the License.
|
|
7
|
-
You may obtain a copy of the License at
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
See the License for the specific language governing permissions and
|
|
13
|
-
limitations under the License.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
// Incrementing OFFLINE_VERSION will kick off the install event and force
|
|
17
|
-
// previously cached resources to be updated from the network.
|
|
18
|
-
const OFFLINE_VERSION = 1;
|
|
19
|
-
const CACHE_NAME = 'offline';
|
|
20
|
-
// Customize this with a different URL if needed.
|
|
21
|
-
const OFFLINE_URL = 'offline.html';
|
|
22
|
-
|
|
23
|
-
self.addEventListener('install', (event) => {
|
|
24
|
-
event.waitUntil(
|
|
25
|
-
(async () => {
|
|
26
|
-
const cache = await caches.open(CACHE_NAME);
|
|
27
|
-
// Setting {cache: 'reload'} in the new request will ensure that the response
|
|
28
|
-
// isn't fulfilled from the HTTP cache; i.e., it will be from the network.
|
|
29
|
-
await cache.add(new Request(OFFLINE_URL, { cache: 'reload' }));
|
|
30
|
-
})(),
|
|
31
|
-
);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
self.addEventListener('activate', (event) => {
|
|
35
|
-
event.waitUntil(
|
|
36
|
-
(async () => {
|
|
37
|
-
// Enable navigation preload if it's supported.
|
|
38
|
-
// See https://developers.google.com/web/updates/2017/02/navigation-preload
|
|
39
|
-
if ('navigationPreload' in self.registration) {
|
|
40
|
-
await self.registration.navigationPreload.enable();
|
|
41
|
-
}
|
|
42
|
-
})(),
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
// Tell the active service worker to take control of the page immediately.
|
|
46
|
-
self.clients.claim();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
self.addEventListener('fetch', (event) => {
|
|
50
|
-
// We only want to call event.respondWith() if this is a navigation request
|
|
51
|
-
// for an HTML page.
|
|
52
|
-
if (event.request.mode === 'navigate') {
|
|
53
|
-
event.respondWith(
|
|
54
|
-
(async () => {
|
|
55
|
-
try {
|
|
56
|
-
// First, try to use the navigation preload response if it's supported.
|
|
57
|
-
const preloadResponse = await event.preloadResponse;
|
|
58
|
-
if (preloadResponse) {
|
|
59
|
-
return preloadResponse;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const networkResponse = await fetch(event.request);
|
|
63
|
-
return networkResponse;
|
|
64
|
-
} catch (error) {
|
|
65
|
-
// catch is only triggered if an exception is thrown, which is likely
|
|
66
|
-
// due to a network error.
|
|
67
|
-
// If fetch() returns a valid HTTP response with a response code in
|
|
68
|
-
// the 4xx or 5xx range, the catch() will NOT be called.
|
|
69
|
-
console.log('Fetch failed; returning offline page instead.', error);
|
|
70
|
-
|
|
71
|
-
const cache = await caches.open(CACHE_NAME);
|
|
72
|
-
const cachedResponse = await cache.match(OFFLINE_URL);
|
|
73
|
-
return cachedResponse;
|
|
74
|
-
}
|
|
75
|
-
})(),
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// If our if() condition is false, then this fetch handler won't intercept the
|
|
80
|
-
// request. If there are any other fetch handlers registered, they will get a
|
|
81
|
-
// chance to call event.respondWith(). If no fetch handlers call
|
|
82
|
-
// event.respondWith(), the request will be handled by the browser as if there
|
|
83
|
-
// were no service worker involvement.
|
|
84
|
-
});
|