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

feat: add endpoint for maps plugin to get info about custom map #898

Merged
merged 7 commits into from
Oct 9, 2024

Conversation

achou11
Copy link
Member

@achou11 achou11 commented Oct 9, 2024

Closes #827

Stacked on #896

  • adds a GET endpoint for the maps plugin located at <prefix>/custom/info to provide the name, size, and creation time of the custom map file if it exists

@achou11 achou11 force-pushed the maps-plugin-refactor branch from abcd13e to fa6b4a2 Compare October 9, 2024 17:26
Base automatically changed from maps-plugin-refactor to main October 9, 2024 17:41
@achou11 achou11 force-pushed the ac/custom-map-info-endpoint branch from 6d4341c to 9475a8b Compare October 9, 2024 17:42
@achou11 achou11 requested a review from gmaclennan October 9, 2024 17:42
@achou11 achou11 marked this pull request as ready for review October 9, 2024 17:42
Copy link
Member

@gmaclennan gmaclennan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Couple of minor niggles, but good to merge even without addressing those.

Comment on lines 33 to 35
const style = await (
await fetch(new URL(`${CUSTOM_MAP_PREFIX}/style.json`, baseUrl))
).json()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe check the response first and pass-through a 404 error.

await fetch(new URL(`${CUSTOM_MAP_PREFIX}/style.json`, baseUrl))
).json()

const stats = await fs.stat(customMapPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should catch an error and if EOENT then 404 maybe? Shouldn't happen because the route above would 404 before here, but for completeness...

const styleJsonName =
typeof style === 'object' &&
style &&
'name' in style &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have this kind of check in so many places in my code and I blame typescript, I can't see any way that it's actually necessary (not saying you shouldn't have it here, just venting!)

url: `/${CUSTOM_MAP_PREFIX}/info`,
})

assert.equal(response.statusCode, 500, 'returns server error status code')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helpful maybe to distinguish "custom map file does not exist" (404) from "custom map file is invalid" (500), since at some point we will probably want different UX for each type, and before then we might want to report actual 500 errors to Sentry, but not 404.

Comment on lines 293 to 297
assert.deepEqual(info, {
created: '2024-10-09T17:41:16.103Z',
size: 2815018,
name: 'MapLibre',
})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any thoughts on the best approach for this assertion? seems like created field is different each time github actions run so it always seems to fail (maybe that's expected??)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stat the file in the test that you are passing to the server, and check the value from the server is the same as what you get from the file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stat the file in the test that you are passing to the server, and check the value from the server is the same as what you get from the file.

@achou11 achou11 requested a review from gmaclennan October 9, 2024 18:53
@achou11 achou11 merged commit 642ba88 into main Oct 9, 2024
6 checks passed
@achou11 achou11 deleted the ac/custom-map-info-endpoint branch October 9, 2024 18:59
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.

Add support for serving Styled Map Package maps
2 participants