Refactor the app
This commit is contained in:
1 parent
f53d39ae69
commit
8f82700736
11 files changed
+2032
-235
No files matched your search
+4
-4
@@ -1,6 +1,6 @@
|
||||
// Streams received files into the browser's download manager. It is the only script besides the app
|
||||
// because service workers can only be registered from a same-origin script URL. Registered with the
|
||||
// scope download/ by src/core.ts, it sees no other requests.
|
||||
// scope download/ by src/download.ts, its counterpart in the page, it sees no other requests.
|
||||
|
||||
// Downloads by id while the page sends chunks: the queue, the stream controller, its wake up, the
|
||||
// reply port and how many bytes the download manager has read.
|
||||
@@ -22,7 +22,7 @@ function open(id, { name, size }, port) {
|
||||
const chunk = download.chunks.shift();
|
||||
if (chunk) {
|
||||
download.read += chunk.byteLength;
|
||||
// Every MiB, src/core.ts forwards it to the sender for its flow control window.
|
||||
// Every MiB, the receiver forwards it to the sender for its flow control window.
|
||||
if (download.read - download.reported >= 2 ** 20) {
|
||||
download.reported = download.read;
|
||||
port.postMessage(download.read);
|
||||
@@ -60,7 +60,7 @@ function open(id, { name, size }, port) {
|
||||
// The page posts the metadata with a reply port first, then every chunk as its own message and
|
||||
// finally done (queued as the end marker null) or an error. Pings come in between.
|
||||
self.addEventListener('message', ({ data, ports: [port] }) => {
|
||||
// Only keeps this worker alive while a transfer stalls, see KEEPALIVE in src/core.ts.
|
||||
// Only keeps this worker alive while a transfer stalls, see KEEPALIVE in src/download.ts.
|
||||
if (data.ping) return;
|
||||
if (port) return open(data.id, data, port);
|
||||
const download = downloads.get(data.id);
|
||||
@@ -77,7 +77,7 @@ self.addEventListener('message', ({ data, ports: [port] }) => {
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
const id = new URL(event.request.url).pathname.split('/').pop();
|
||||
// download/ itself is the empty page src/core.ts keeps open to hold this worker during a transfer.
|
||||
// download/ itself is the empty page src/download.ts keeps open to hold this worker during a transfer.
|
||||
if (!id)
|
||||
return event.respondWith(
|
||||
new Response('<!doctype html>', { headers: { 'Content-Type': 'text/html; charset=utf-8' } }),
|
||||
|
||||
Reference in new issue
Block a user