core icon indicating copy to clipboard operation
core copied to clipboard

Fetch: How to update index?

Open kachurun opened this issue 11 months ago • 3 comments

Hi! Thank you for an amazing tool! But it definitely has a lack of documentation, and now I can't understand how I can reload the index with FetchFS in case the files have changed on my server.

I have code like this:

export const mountBrowserFS = async(mountDir: string, baseUrl: string) => {
    const fetchFS = await resolveMountConfig({
        backend: Fetch,
        index: `${ baseUrl }/index.json`,
        baseUrl,
        disableAsyncCache: true,
        remoteWrite: true,
    });

    mount(mountDir, fetchFS);

    return true;
};

So I have an idea to unmount before mounting, but it feels a little bit dirty.

kachurun avatar May 15 '25 20:05 kachurun

Hey @kachurun, thanks for reaching out.

There isn't currently a method for reloading the index, though I would be willing to add it.

As for normal, I recommend you use the configure/configureSingle functions.

In case you weren't aware, there is extensive documentation available on zenfs.dev.

james-pre avatar May 16 '25 00:05 james-pre

@james-pre Thank you for fast answer!

I did this:

import '@common_src/polyfills/buffer';
import { Fetch, mount, resolveMountConfig, umount } from '@zenfs/core';

const mounted = new Map<string, boolean>();

export const unmountBrowserFS = (mountDir: string) => {
    if (mounted.has(mountDir)) {
        umount(mountDir);
        mounted.delete(mountDir);

        return true;
    }

    return false;
};

export const mountBrowserFS = async(mountDir: string, baseUrl: string) => {
    unmountBrowserFS(mountDir);

    const fetchFS = await resolveMountConfig({
        backend: Fetch,
        index: `${ baseUrl }/index.json`,
        baseUrl,
        disableAsyncCache: true,
        remoteWrite: true,
    });

    mount(mountDir, fetchFS);
    mounted.set(mountDir, true);

    return true;
};

And it works great. Not sure configure fits well for this, because I'm going to dynamically mount and remove filesystems depending on the project opened by the user in some SPA app.

kachurun avatar May 16 '25 00:05 kachurun

Okay.

I'll definitely be adding a way to reload/sync the index. This could tie in nicely to the future DAV backend, since that would likely fit the use case better.

james-pre avatar May 16 '25 00:05 james-pre