Skip to content

Commit

Permalink
feat(lambda-xyz): Serve local images with set priority
Browse files Browse the repository at this point in the history
dir format:

2193-serve/100_sentinel/03202112.tiff
2193-serve/100_sentinel/03202131.tiff
2193-serve/100_sentinel/03203.tiff
...
2193-serve/500_auckland/032211032.tiff
...
2193-serve/500_wellington/032233223.tiff
...
  • Loading branch information
Geoff Jacobsen committed Jun 10, 2020
1 parent b93a0de commit a50e6c9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/lambda-xyz/src/cli/tile.set.local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { CogSourceAwsS3 } from '@cogeotiff/source-aws';
import { CogSourceFile } from '@cogeotiff/source-file';
import { TileSet } from '../tile.set';
import { Epsg } from '@basemaps/geo';
import { promises as fsPromises } from 'fs';
import { join } from 'path';

function getTiffs(fs: FileProcessor, tiffList: string[]): CogSource[] {
if (fs instanceof FileOperatorS3) {
Expand Down Expand Up @@ -43,7 +45,20 @@ export class TileSetLocal extends TileSet {

const fileList = isTiff(this.filePath) ? [this.filePath] : await tiffFs.list(this.filePath);
const files = fileList.filter(isTiff);
if (files.length == 0) throw new Error(`No tiff files found in ${this.filePath}`);
if (files.length == 0 && !FileOperator.isS3(this.filePath)) {
for (const dir of fileList.sort()) {
const st = await fsPromises.stat(dir);
if (st.isDirectory()) {
for (const file of await fsPromises.readdir(dir)) {
const filePath = join(dir, file);
if (isTiff(filePath)) files.push(filePath);
}
}
}
}
if (files.length == 0) {
throw new Error(`No tiff files found in ${this.filePath}`);
}

this.tiffs = getTiffs(tiffFs, files).map((c) => new CogTiff(c));

Expand Down

0 comments on commit a50e6c9

Please sign in to comment.