Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for omitting a filename #21

Merged
merged 4 commits into from
Sep 10, 2017
Merged

Conversation

jczaplew
Copy link
Contributor

@jczaplew jczaplew commented Sep 1, 2017

Adds the option noFilename to the main tilestrata configuration parameters to allow for the {z}/{x}/{y}.{extension} request format.

While this is a global setting, I can also see arguments for having it be a route-specific parameter.

To use it, simply pass {noFilename: true} when initializing the the tileserver, and pass the file extension in place of the filename (.route('png')) .

Let me know what you think!

@jczaplew jczaplew changed the title Nofilename Option for omitting a filename Sep 1, 2017
@codecov-io
Copy link

codecov-io commented Sep 1, 2017

Codecov Report

Merging #21 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #21      +/-   ##
==========================================
+ Coverage   97.51%   97.52%   +<.01%     
==========================================
  Files           8        8              
  Lines         685      686       +1     
==========================================
+ Hits          668      669       +1     
  Misses         17       17
Impacted Files Coverage Δ
lib/TileRequest.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 13dc551...ad230aa. Read the comment docs.

@brianreavis
Copy link
Member

Thanks for taking a stab at this @jczaplew! One concern is that as this is now it'll cause certain problems downstream in plugins that currently expect filename to be indicative of the mime type. The tilestrata-disk plugin is what comes to mind: https://github.com/naturalatlas/tilestrata-disk/blob/master/lib/cache.js#L101

The quick fix is to make req.filename have a dot in front (.png vs png).

Instead of a noFilename option, what do you think about making it configurable per route like you hinted about with some sort of convention like a leading * (that we could note in the readme):

.route('*.png')

Once we get this worked out, I'd love to get this in! I have a feeling it'll make quite a few people happy.

@jczaplew
Copy link
Contributor Author

jczaplew commented Sep 4, 2017

Sounds good @brianreavis! Makes a lot of sense.

Another oddity that I'm not sure is a concern or not is that this approach will result in caches like tilestrata-disk saving the tiles as /{z}/{x}/{y}/*.{extension}, when ideally they would be saved as /{z}/{x}/{y}.{extension} instead. It certainly works and I don't see many drawbacks besides a lack of elegance. Perhaps it is something that can be optionally changed on the caches themselves.

@jczaplew
Copy link
Contributor Author

@brianreavis - is there anything else you would like changed on this pull?

@brianreavis
Copy link
Member

Oops, sorry – fell off my radar. Thanks for the nudge! Going to merge this as it is and make some subtle changes to address some of the questions you bring up. Might be easier to do it than try to articulate :)

Really appreciate the work on this!

@brianreavis brianreavis merged commit 50cb36c into naturalatlas:master Sep 10, 2017
brianreavis added a commit that referenced this pull request Sep 11, 2017
…tyle routes + documentation / more tests
@brianreavis
Copy link
Member

Alright, this is now out in 2.1.0. Thanks for tackling the bulk of this @jczaplew! To sum up the adjustments in e002a71:

  • Made resolution suffixes parse fine. e.g. route('*@2x.png')
  • Exposed hasFilename on TileRequest
  • Made the filename convention "t" + extension for these sorts of requests. This way we don't end up with filenames with asterisks and it's totally backwards-compatible with everything. I thought about just stripping the * off, but leaving people with dotfiles (that some OS's hide by default) didn't seem like a great idea either.
    • Although it is a little funky, I think it's fine if the convention is clear and we expose hasFilename to make it transparent.
  • More tests / documentation

Just as a footnote, if you want a cache layout that matches the urls for whatever reason, something like this (ish) would work:

var dest = req.z + '/' + req.x + '/' + req.y;
if (req.hasFilename) {
   dest += '/' + req.filename;
} else {
   dest += req.filename.substring(1);
}

@jczaplew
Copy link
Contributor Author

Awesome! Thanks a ton @brianreavis!

brianreavis added a commit to naturalatlas/tilestrata-dependency that referenced this pull request Oct 10, 2017
Should have done this the 2.1.0 release, but it slipped my mind.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants