@banou/ripple 0.0.42 → 0.0.43
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/assets/worker-b6xs3k5Q.js +27 -0
- package/fkn.json +1 -1
- package/index.js +778 -767
- package/package.json +1 -1
- package/sw.js +61 -14
- package/assets/worker-BBuQVIu1.js +0 -27
package/package.json
CHANGED
package/sw.js
CHANGED
|
@@ -8,8 +8,8 @@ const live = new Map()
|
|
|
8
8
|
/* Stamped at build time. These are the dev defaults and must never reach production: a worker whose
|
|
9
9
|
BUILD never changes is never reinstalled, so the update this feature announces would never fire. */
|
|
10
10
|
const MODE = "cache" // @stamp:mode
|
|
11
|
-
const BUILD = "
|
|
12
|
-
const MANIFEST = [["/ar-CS4Yzfxw-ntfoSy6g.js","964b11fd5f334eb5"],["/assets/empty-BvRk9kiK.js","e3b0c44298fc1c14"],["/assets/libtorrent-DL9DAt4E.js","7e904fbc35c48a99"],["/assets/worker-
|
|
11
|
+
const BUILD = "a6dc8b189cde589e" // @stamp:build
|
|
12
|
+
const MANIFEST = [["/ar-CS4Yzfxw-ntfoSy6g.js","964b11fd5f334eb5"],["/assets/empty-BvRk9kiK.js","e3b0c44298fc1c14"],["/assets/libtorrent-DL9DAt4E.js","7e904fbc35c48a99"],["/assets/worker-b6xs3k5Q.js","6285369d6b96c3e3"],["/build-B7te3F-u.js","47b056c564f078c5"],["/cs-CxBZ1aTx-DJlDhThf.js","237f800faa98cd58"],["/de-DphEdq0O-Cx5KYfi3.js","01ef03045bb165d7"],["/de-f2AVyBur.js","49a5533acb7816c7"],["/el-BVTNfAWK-DR4z_l3g.js","ea1d24cef818bf1c"],["/es-419-CjvXqRKH.js","909f5f2df305145f"],["/es-419-D6gsvnn8-DPOi-mTp.js","20f64ebce9f90902"],["/fr-BqAWZMOU.js","12fd8bc6123982b7"],["/fr-BqAzAJX0-tO4ZnrRx.js","e33d69ca8b541855"],["/he-DbFw1CdO-BQBjAJw3.js","7a23f52d225a8886"],["/hi-rBroV7g8-BKMVjsFT.js","b3d4e2c47108797e"],["/hu-m-QKaaxF-BMZqq-7P.js","4fe38f630e548e32"],["/id-BYpApdK9-Dkgrchef.js","4cd2e6bf0fa71b8c"],["/it-NTcUh3Gr-lPnPd57N.js","953112fe77329a13"],["/it-YU3KUI8-.js","366bb9a446e52474"],["/ja-B7820KaN.js","25d406718aa816bc"],["/ja-DSmX_bxj-CtZfcziw.js","aca442500d0de101"],["/ko-CwzPeJqO.js","513785cf79dddbb7"],["/ko-DyPzWasj-BzWTky6S.js","649c13521707e1c2"],["/ms-8pQbqM0D-CqJOEt8R.js","3f04e1a54b542ccf"],["/nl-q7xvc3xW-wNb_UuNc.js","a7fc209b29f0315c"],["/pl-BbzVHslS.js","233a5bd3f57f5d54"],["/pl-C6Ow4ra5-DnFaIeqF.js","086d34bcaf3149a8"],["/pt-BR-ClZSKJdC.js","d813d5459e25718a"],["/pt-BR-wudK3giz-CNnIslbU.js","a424e6d1d126df8b"],["/remote-CbOGAlJZ.js","26b779287dedd5a7"],["/ro-DBrd08Df-DVgJ76rr.js","40ede477e1748f46"],["/ru-B030ilIg.js","d55f83a1909793ee"],["/ru-D5kxBkik-Co3SZGx7.js","197a1d10d93e6e3a"],["/sv-DJC3tXfW-CtNN1hTP.js","29684bbd94d0bb03"],["/th-BNzU_FYo-R9JeWVkr.js","f58ad889fff6a5f7"],["/tr-CW7R7N9k-CKbYpVyF.js","2390ab78e3131452"],["/tr-Cle6lDex.js","b9f6af54bdf839f4"],["/uk-C66esN2W-BVOzQwRO.js","09bc106f3b654f3e"],["/vi-oOaDECwu-P7-ObqFb.js","0bcec07acef89832"],["/zh-Hans-E0lR_xLM.js","89390ab5619adf32"],["/zh-Hans-IhL1Pl78-BSKvaC2F.js","a17cdbec76937b0d"],["/zh-Hant-C5YyFjEc-Dghd5nFF.js","681482004d10d75e"],["/zh-Hant-DwmkgxT0.js","106a785e6fc48e89"]] // @stamp:manifest
|
|
13
13
|
|
|
14
14
|
const CACHE = 'ripple-assets-' + BUILD
|
|
15
15
|
/** Holds the name of the generation that activated last, so the next activation can keep it. */
|
|
@@ -103,18 +103,27 @@ self.addEventListener('activate', (event) => {
|
|
|
103
103
|
})())
|
|
104
104
|
})
|
|
105
105
|
|
|
106
|
+
/*
|
|
107
|
+
* Chrome keeps a page that left mid-save in its back-forward cache for up to 10 minutes, and one brought back goes on
|
|
108
|
+
* pinging every 10 s and feeding the save. Evicted, it says nothing, and Chrome keeps this worker and the download in
|
|
109
|
+
* progress for good (Chromium 156: still in progress 13 minutes later). So a save whose page has not pinged for 11
|
|
110
|
+
* minutes is failed. Counted in minutes rather than timed, so a machine waking from sleep is not taken for a page gone.
|
|
111
|
+
*/
|
|
112
|
+
const SILENT_MINUTES = 11
|
|
113
|
+
|
|
106
114
|
self.addEventListener('message', (event) => {
|
|
107
115
|
const data = event.data
|
|
108
116
|
if (!data) return
|
|
109
117
|
if (data.type === 'stream-open') {
|
|
110
118
|
const port = event.ports[0]
|
|
111
119
|
if (!port) return
|
|
112
|
-
live.set(data.id, { name: data.name, size: data.size, port, resolvePull: null })
|
|
120
|
+
live.set(data.id, { name: data.name, size: data.size, port, resolvePull: null, silent: 0 })
|
|
113
121
|
port.postMessage({ type: 'stream-ready' })
|
|
114
122
|
return
|
|
115
123
|
}
|
|
116
124
|
// Answered only while the download is still live: a worker killed mid-download comes back with an empty map.
|
|
117
125
|
if (data.type === 'ping' && live.has(data.id) && event.source) {
|
|
126
|
+
live.get(data.id).silent = 0
|
|
118
127
|
event.source.postMessage({ type: 'pong', id: data.id })
|
|
119
128
|
return
|
|
120
129
|
}
|
|
@@ -126,9 +135,31 @@ self.addEventListener('message', (event) => {
|
|
|
126
135
|
}
|
|
127
136
|
})
|
|
128
137
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
138
|
+
/*
|
|
139
|
+
* Chromium 156 cancels a save named 250 UTF-8 bytes or more and Firefox 157 one of 244 or more, with no word to the
|
|
140
|
+
* page (measured on Linux, whose names hold 255 bytes: each browser writes under a longer temporary name first). So a
|
|
141
|
+
* longer name is cut, keeping its extension.
|
|
142
|
+
*/
|
|
143
|
+
const MAX_NAME_BYTES = 200
|
|
144
|
+
const utf8Bytes = (text) => new TextEncoder().encode(text).length
|
|
145
|
+
const fitName = (name) => {
|
|
146
|
+
if (utf8Bytes(name) <= MAX_NAME_BYTES) return name
|
|
147
|
+
const dot = name.lastIndexOf('.')
|
|
148
|
+
const extension = dot > 0 && name.length - dot <= 10 ? name.slice(dot) : ''
|
|
149
|
+
let stem = ''
|
|
150
|
+
for (const char of name.slice(0, name.length - extension.length)) {
|
|
151
|
+
if (utf8Bytes(stem + char + extension) > MAX_NAME_BYTES) break
|
|
152
|
+
stem += char
|
|
153
|
+
}
|
|
154
|
+
return stem + extension
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// A header value holds no character above U+00FF, so the quoted name is ASCII and the browsers save under filename*
|
|
158
|
+
// (RFC 6266), which carries the real one.
|
|
159
|
+
const disposition = (asked) => {
|
|
160
|
+
const name = fitName(String(asked || 'download'))
|
|
161
|
+
const safe = name.replace(/[^\x20-\x7e]|["\\]/g, '_')
|
|
162
|
+
return `attachment; filename="${safe}"; filename*=UTF-8''${encodeURIComponent(name)}`
|
|
132
163
|
}
|
|
133
164
|
|
|
134
165
|
self.addEventListener('fetch', (event) => {
|
|
@@ -170,9 +201,27 @@ self.addEventListener('fetch', (event) => {
|
|
|
170
201
|
return
|
|
171
202
|
}
|
|
172
203
|
|
|
204
|
+
let headers
|
|
205
|
+
try {
|
|
206
|
+
headers = new Headers({
|
|
207
|
+
'Content-Type': 'application/octet-stream',
|
|
208
|
+
'Content-Disposition': disposition(entry.name),
|
|
209
|
+
'Cache-Control': 'no-store',
|
|
210
|
+
})
|
|
211
|
+
} catch {
|
|
212
|
+
// Unanswered, the frame would get the app's page and the page would wait for bytes forever.
|
|
213
|
+
live.delete(id)
|
|
214
|
+
entry.port.postMessage({ type: 'error' })
|
|
215
|
+
event.respondWith(new Response('Download failed', { status: 500 }))
|
|
216
|
+
return
|
|
217
|
+
}
|
|
218
|
+
// Only when it is known exactly: a zip's length is not known until it has been written.
|
|
219
|
+
if (entry.size > 0) headers.set('Content-Length', String(entry.size))
|
|
220
|
+
|
|
173
221
|
const finish = () => {
|
|
174
222
|
if (entry.done) return
|
|
175
223
|
entry.done = true
|
|
224
|
+
clearInterval(entry.watch)
|
|
176
225
|
live.delete(id)
|
|
177
226
|
const resolve = entry.resolvePull
|
|
178
227
|
entry.resolvePull = null
|
|
@@ -181,6 +230,12 @@ self.addEventListener('fetch', (event) => {
|
|
|
181
230
|
|
|
182
231
|
const body = new ReadableStream({
|
|
183
232
|
start(controller) {
|
|
233
|
+
entry.watch = setInterval(() => {
|
|
234
|
+
if (++entry.silent <= SILENT_MINUTES) return
|
|
235
|
+
controller.error(new Error('the page is gone'))
|
|
236
|
+
entry.port.postMessage({ type: 'error' })
|
|
237
|
+
finish()
|
|
238
|
+
}, 60_000)
|
|
184
239
|
entry.port.onmessage = (e) => {
|
|
185
240
|
const msg = e.data
|
|
186
241
|
if (!msg || entry.done) return
|
|
@@ -215,13 +270,5 @@ self.addEventListener('fetch', (event) => {
|
|
|
215
270
|
},
|
|
216
271
|
})
|
|
217
272
|
|
|
218
|
-
const headers = {
|
|
219
|
-
'Content-Type': 'application/octet-stream',
|
|
220
|
-
'Content-Disposition': disposition(entry.name),
|
|
221
|
-
'Cache-Control': 'no-store',
|
|
222
|
-
}
|
|
223
|
-
// Only when it is known exactly: a zip's length is not known until it has been written.
|
|
224
|
-
if (entry.size > 0) headers['Content-Length'] = String(entry.size)
|
|
225
|
-
|
|
226
273
|
event.respondWith(new Response(body, { headers }))
|
|
227
274
|
})
|