-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
abcd13e
to
fa6b4a2
Compare
6d4341c
to
9475a8b
Compare
There was a problem hiding this 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.
src/fastify-plugins/maps.js
Outdated
const style = await ( | ||
await fetch(new URL(`${CUSTOM_MAP_PREFIX}/style.json`, baseUrl)) | ||
).json() |
There was a problem hiding this comment.
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.
src/fastify-plugins/maps.js
Outdated
await fetch(new URL(`${CUSTOM_MAP_PREFIX}/style.json`, baseUrl)) | ||
).json() | ||
|
||
const stats = await fs.stat(customMapPath) |
There was a problem hiding this comment.
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 && |
There was a problem hiding this comment.
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!)
test/fastify-plugins/maps.js
Outdated
url: `/${CUSTOM_MAP_PREFIX}/info`, | ||
}) | ||
|
||
assert.equal(response.statusCode, 500, 'returns server error status code') |
There was a problem hiding this comment.
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.
test/fastify-plugins/maps.js
Outdated
assert.deepEqual(info, { | ||
created: '2024-10-09T17:41:16.103Z', | ||
size: 2815018, | ||
name: 'MapLibre', | ||
}) |
There was a problem hiding this comment.
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??)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Closes #827
Stacked on #896
<prefix>/custom/info
to provide the name, size, and creation time of the custom map file if it exists