Skip to content

Have the render function for dirlist work for json as well #221

@lordnox

Description

@lordnox

🚀 Feature Proposal

With an optional render function for dirlist we could change the results for the json output by either removing files we don't want to show (filter all non-images) or send more data (adding more stats, mimetype or other data)

Motivation

I'd like to have a image server running that connects to a directory and only sends out images, the client should not see other data

Example

  fastify.register(fastifyStatic, {
    root: path.resolve(options.imagePath),
    prefix: options.path,
    dotfiles: 'ignore',
    list: {
      format: 'json',
      names: ['index', 'index.json', '/', ''],
      render: (files, dirs) => {
        return {
          files: files.filter(file => !isImage(file)).map(file => generateImageInfo(file)),
          dirs,
        }
      }
    },
  })

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomerssemver-minorIssue or PR that should land as semver minor

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions