supabase-community / storage-csharp

A C# implementation of Supabase's Object Storage API
https://supabase-community.github.io/storage-csharp/api/Supabase.Storage.Client.html
MIT License
19 stars 7 forks source link

Add "recursive listing" option to files List function #18

Open HighPriest opened 2 months ago

HighPriest commented 2 months ago

Feature request

Problem

I would like to store two types of configuration files, accessible from one bucket, through one auth key.
It would also be convenient for a deeper folder structure to exist.

Describe the solution

When I "List" all files in a bucket, or directory. I would like to have an option for all the files in sub-directories to also be listed, with their full & relative paths. It would be nice if there was an endpoint we could query directly for data already structured, rather than manually querying every path, which is not a file.

Describe alternatives you've considered

I can make a direct query for contents of the objects table in the Postgres database. But this is neither convenient, nor safe (or easy to make safe).

HighPriest commented 2 months ago

FYI.
I use this little monster to get ALL the files in a bucket:

        public void ListAllFiles()
        {
            public_files = new List<Supabase.Storage.FileObject>();

            foreach (Supabase.Storage.FileObject _file in Task.Run(() => supabase.Storage.From("Public").List()).GetAwaiter().GetResult())
            {
                recursiveSupabaseFileListing(_file, "");
            }
            foreach (var file in public_files)
            {
                Debug.WriteLine("File Name: " + file.Name);
            }
            Debug.WriteLine("FilesListed: " + status);
        }

        public void recursiveSupabaseFileListing(FileObject file, string path)
        {
            string _path = path.IsNullOrEmpty() ? file.Name : String.Join("/", path, file.Name);

            if (!file.IsFolder)
            {
                file.Name = _path;
                public_files.Add(file);
                return;
            }

            var files = Task.Run(() => supabase.Storage.From("Public").List(path: _path)).GetAwaiter().GetResult();

            Debug.WriteLine(_path);

            foreach (Supabase.Storage.FileObject _files in files)
            {
                recursiveSupabaseFileListing(_files, _path);
            }
        }
acupofjose commented 2 months ago

Thanks for the issue @HighPriest - this doesn't look like it's supported from the Supabase Storage server as an endpoint, nor is it implemented in the JS client. I think you should open an issue up on the server repo to have them implement an endpoint rather than us hacking together a solution on the client!