serve-index icon indicating copy to clipboard operation
serve-index copied to clipboard

allow returning file details in JSON

Open adamarthurryan opened this issue 10 years ago • 4 comments

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?

adamarthurryan avatar Nov 13 '15 02:11 adamarthurryan

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.)

adamarthurryan avatar Nov 13 '15 02:11 adamarthurryan

Ah, also, I guess I used some too-newfangled JS in my testing code. I'll revise that.

adamarthurryan avatar Nov 13 '15 04:11 adamarthurryan

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?

dougwilson avatar Aug 12 '18 06:08 dougwilson

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?

coolaj86 avatar Aug 13 '18 14:08 coolaj86