serve-index
serve-index copied to clipboard
allow returning file details in JSON
I'm proposing a patch that allows fs.Stats file info to be returned in JSON. This is be enabled by the jsonStat option. The stat fields properties are screened to only pass a machine-neutral subset (ie. not exposing user ids, device ids, etc.). Also, the isFile() and isDirectory() function return values are encoded as properties.
Any thoughts on this?
I'm not sure that the selection of properties returned is quite right. Perhaps it would make sense to depart from the fs.Stats format and come up with a better list of relevant properties. (Eg. type=[file|dir], readable, writable, created, modified, etc.)
Ah, also, I guess I used some too-newfangled JS in my testing code. I'll revise that.
I like this idea, sorry this repo has been on the side lines for a while. Any interest in rebasing it to the latest master / making the JS change you mentioned?
I’ve also created a PR for this.
https://github.com/expressjs/serve-index/issues/74
My implementation is slightly different in that it adheres to the W3 File API:
- name
- size
- type
- lastModified
Type is “inode/directory” for dirs.
With my string of commits the goal is to provide the same subset of data to all of the serveIndex template functions (plain, json, html) and pave a way forward for separating the security and functionality from the view and layout so that it’s easy to publish and use a “theme” module to handle diverse needs rather than having to fork serve-index itself and potentially fall behind.
Does that work for your use case? Or do you specifically need access time and the date of creation?