trannamtrung1st / elFinder.Net.Core

An elFinder backend connector with less magic code and more compatibility. This enables .NET Standard 2.0 projects to easily integrate elFinder functionalities.
Apache License 2.0
12 stars 8 forks source link

Create Custom FileSystemDirectory #42

Closed benny-adiwijaya closed 10 months ago

benny-adiwijaya commented 11 months ago

Hi, I need to create custom FileSystemDirectory. I already create new class that inherits from FileSystemDirectory

public class ApplicationFileSystemDirectory : FileSystemDirectory
    {
        public ApplicationFileSystemDirectory(string dirName, IVolume volume) : base(dirName, volume)
        {
        }

        public override Task<IEnumerable<IFile>> GetFilesAsync(string search, bool verify = true,
            Func<IFile, bool> filter = null, SearchOption searchOption = default, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (search == null) throw new ArgumentNullException(nameof(search));

            if (verify && !ObjectAttribute.Read) return Task.FromResult<IEnumerable<IFile>>(new IFile[0]);

            if (!search.Contains('*'))
                search = '*' + search + '*';

            var files = directoryInfo.EnumerateFiles(search, searchOption).Select(f => new FileSystemFile(f, volume) as IFile);

            if (filter != null) files = files.Where(filter);
            else files = files.Where(file => file.ObjectAttribute.Visible);

            return Task.FromResult(files);
        }
    }

How to register custom FileSystemDirectory class in program.cs / StartUp.cs?

trannamtrung1st commented 10 months ago

Sorry for my late reply. I might have missed the notification. I don't think there is any easy way for now, you'll have to customize the FileSystemDriver and FileSystemFile as well. image