jimmywarting / native-file-system-adapter

File system, based on the spec reference implementation

Home Page:https://jimmywarting.github.io/native-file-system-adapter/example/test.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: webpack setup with react

PaulTime opened this issue · comments

Hello, could you help me? I'm trying to run this repo with webpack and react
I've copied sources and installed web-stream-polyfill/ponyfill
this is my code from sw

const map = new Map();

// This should be called once per download
// Each event has a dataChannel that the data will be piped through
addEventListener('message', evt => {
  const data = evt.data;

  if (!data.rs && evt.ports[0]) data.rs = createStream(evt.ports[0]);
  map.set(data.url, data)
});

addEventListener('fetch', evt => {
  const url = evt.request.url;
  const data = map.get(url);
  if (!data) return null;
  map.delete(url);
  evt.respondWith(new Response(data.rs, {
    headers: data.headers
  }))
});

and use lib like this

const { chooseFileSystemEntries } = await import('services/native-file-system-adapter/src/es6');

    const fileHandle = await chooseFileSystemEntries({
      type: 'save-file',
      accepts: [
        { extensions: [name.split('.').pop()] },
        { mimeTypes: [type] },
      ],
      excludeAcceptAllOption: true,
      _preferPolyfill: false,
      _name: name,
    });

    const writable = await fileHandle.createWritable();

    const body$ = await fetch(url, { credentials: 'include' }).then(res => res.body);

    // const totalFileBuffers: Uint8Array[] = [];

    const { data: decrypted$ } = await openpgp.decrypt({
      message: await openpgp.message.read(body$),
      passwords: randomKey,
      format: 'binary',
      streaming: 'web',
    });

    await decrypted$.pipeTo(writable);

but nothin happens (but it works with experimental Native File System being enabled)
where can I be mistaken?

found that https://github.com/jimmywarting/native-file-system-adapter/blob/master/src/adapters/downloader.js#L61 uses variable name which has value of undefined
changed name to fileName but it didn't change anything

finally, I've figured it out.
my sw.js was caching every navigation route

registerRoute(
  new NavigationRoute(createHandlerBoundToURL(`${process.env.PUBLIC_PATH}index.html`))
);

once I commented those lines it all worked great))