Skip to content

Commit

Permalink
fix(lambda-tiler): do not error when invalid imagery urls are provided (
Browse files Browse the repository at this point in the history
#2133)

* feat(lambda-tiler): allow fetching of the cutline used on the imagery

* fix(lambda-tiler): support unprefixed imagery ids too

* refactor: cutlines are too big do not allow sending them directly

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
blacha and kodiakhq[bot] authored Apr 5, 2022
1 parent 9e7b508 commit 8211428
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 13 additions & 0 deletions packages/lambda-tiler/src/routes/__test__/imagery.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import o from 'ospec';
import { isAllowedFile } from '../imagery.js';

o.spec('ImageryRoute', () => {
o('should allow geojson and json files only', () => {
o(isAllowedFile('foo.geojson')).equals(true);
o(isAllowedFile('foo.json')).equals(true);
o(isAllowedFile('foo.tiff')).equals(false);
o(isAllowedFile('foo')).equals(false);
o(isAllowedFile('')).equals(false);
o(isAllowedFile(null as any)).equals(false);
});
});
12 changes: 8 additions & 4 deletions packages/lambda-tiler/src/routes/imagery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { TileEtag } from './tile.etag.js';

const gzipP = promisify(gzip);

function isAllowedFile(f: string): boolean {
export function isAllowedFile(f: string): boolean {
if (f == null) return false;
if (f.endsWith('.geojson')) return true;
if (f.endsWith('.json')) return true;
return false;
Expand All @@ -20,15 +21,18 @@ function isAllowedFile(f: string): boolean {
* Get metadata around the imagery such as the source bounding box or the bounding box of the COGS
*
* @example
* - /v1/imagery/:imageryId/source.geojson
* - /v1/imagery/:imageryId/covering.geojson
* - /v1/imagery/:imageryId/source.geojson - Source boudning boxes
* - /v1/imagery/:imageryId/covering.geojson - Output tile bounding boxes
* - /v1/imagery/:imageryId/cutline.geojson - Cutline used ont he imagery set
* - /v1/imagery/:imageryId/collection.json - STAC Collection
* - /v1/imagery/:imageryId/15-32659-21603.json - STAC Item
*/
export async function Imagery(req: LambdaHttpRequest): Promise<LambdaHttpResponse> {
const { rest } = Router.action(req);
const [imageryId, requestType] = rest;
if (!isAllowedFile(requestType)) return new LambdaHttpResponse(404, 'Not found');

const imagery = await Config.Imagery.get(imageryId);
const imagery = await Config.Imagery.get(Config.Imagery.id(imageryId));
if (imagery == null) return new LambdaHttpResponse(404, 'Not found');

const targetPath = fsa.join(imagery.uri, requestType);
Expand Down

0 comments on commit 8211428

Please sign in to comment.