-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from dfpc-coe/mission-cots
TS Strict Mode
- Loading branch information
Showing
42 changed files
with
2,442 additions
and
948 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,85 @@ | ||
import Err from '@openaddresses/batch-error'; | ||
import path from 'path'; | ||
import S3 from '../lib/aws/s3.js'; | ||
import { _Object } from '@aws-sdk/client-s3'; | ||
|
||
import Config from '../lib/config.js'; | ||
|
||
export default async function AssetList(config: Config, prefix: string) { | ||
export type AssetListOutput = { | ||
total: number; | ||
tiles: { | ||
url: string; | ||
}, | ||
assets: Array<AssetOutput> | ||
} | ||
|
||
export type AssetOutput = { | ||
name: string; | ||
visualized?: string; | ||
vectorized?: string, | ||
updated: number; | ||
etag: string; | ||
size: number; | ||
} | ||
|
||
export default async function AssetList(config: Config, prefix: string): Promise<AssetListOutput> { | ||
try { | ||
const viz = new Map() ; | ||
const geo = new Map() ; | ||
let assets = []; | ||
(await S3.list(prefix)).map((l) => { | ||
if (path.parse(l.Key).ext === '.pmtiles') viz.set(path.parse(l.Key).name, l) | ||
else if (path.parse(l.Key).ext === '.geojsonld') geo.set(path.parse(l.Key).name, l) | ||
else assets.push(l) | ||
}); | ||
const assets: Array<_Object> = []; | ||
(await S3.list(prefix)) | ||
.map((l) => { | ||
if (path.parse(String(l.Key)).ext === '.pmtiles') viz.set(path.parse(String(l.Key)).name, l) | ||
else if (path.parse(String(l.Key)).ext === '.geojsonld') geo.set(path.parse(String(l.Key)).name, l) | ||
else assets.push(l) | ||
}); | ||
|
||
assets = assets.map((a) => { | ||
const isViz = viz.get(path.parse(a.Key).name); | ||
if (isViz) viz.delete(path.parse(a.Key).name); | ||
const isGeo = geo.get(path.parse(a.Key).name); | ||
if (isGeo) geo.delete(path.parse(a.Key).name); | ||
const final: AssetOutput[] = assets.map((a: _Object) => { | ||
const isViz = viz.get(path.parse(String(a.Key)).name); | ||
if (isViz) viz.delete(path.parse(String(a.Key)).name); | ||
const isGeo = geo.get(path.parse(String(a.Key)).name); | ||
if (isGeo) geo.delete(path.parse(String(a.Key)).name); | ||
|
||
return { | ||
name: a.Key.replace(prefix, ''), | ||
visualized: isViz ? path.parse(a.Key.replace(prefix, '')).name + '.pmtiles' : false, | ||
vectorized: isGeo ? path.parse(a.Key.replace(prefix, '')).name + '.geojsonld' : false, | ||
updated: new Date(a.LastModified).getTime(), | ||
etag: JSON.parse(a.ETag), | ||
size: a.Size | ||
name: String(a.Key).replace(prefix, ''), | ||
visualized: isViz ? path.parse(String(a.Key).replace(prefix, '')).name + '.pmtiles' : undefined, | ||
vectorized: isGeo ? path.parse(String(a.Key).replace(prefix, '')).name + '.geojsonld' : undefined, | ||
updated: a.LastModified ? new Date(a.LastModified).getTime() : new Date().getTime(), | ||
etag: String(JSON.parse(String(a.ETag))), | ||
size: a.Size ? a.Size : 0 | ||
}; | ||
}).concat(Array.from(geo.values()).map((a) => { | ||
const isViz = viz.get(path.parse(a.Key).name); | ||
if (isViz) viz.delete(path.parse(a.Key).name); | ||
const isViz = viz.get(path.parse(String(a.Key)).name); | ||
if (isViz) viz.delete(path.parse(String(a.Key)).name); | ||
|
||
return { | ||
name: a.Key.replace(prefix, ''), | ||
visualized: isViz ? path.parse(a.Key.replace(prefix, '')).name + '.pmtiles' : false, | ||
vectorized: a.Key.replace(prefix, ''), | ||
updated: new Date(a.LastModified).getTime(), | ||
etag: JSON.parse(a.ETag), | ||
size: a.Size | ||
name: String(a.Key).replace(prefix, ''), | ||
visualized: isViz ? path.parse(String(a.Key).replace(prefix, '')).name + '.pmtiles' : undefined, | ||
vectorized: String(a.Key).replace(prefix, ''), | ||
updated: a.LastModified ? new Date(a.LastModified).getTime() : new Date().getTime(), | ||
etag: String(JSON.parse(String(a.ETag))), | ||
size: a.Size ? a.Size : 0 | ||
}; | ||
|
||
})).concat(Array.from(viz.values()).map((a) => { | ||
return { | ||
name: a.Key.replace(prefix, ''), | ||
visualized: a.Key.replace(prefix, ''), | ||
vectorized: false, | ||
updated: new Date(a.LastModified).getTime(), | ||
etag: JSON.parse(a.ETag), | ||
size: a.Size | ||
name: String(a.Key).replace(prefix, ''), | ||
visualized: String(a.Key).replace(prefix, ''), | ||
vectorized: undefined, | ||
updated: a.LastModified ? new Date(a.LastModified).getTime() : new Date().getTime(), | ||
etag: String(JSON.parse(String(a.ETag))), | ||
size: a.Size ? a.Size : 0 | ||
}; | ||
})); | ||
|
||
return { | ||
total: assets.length, | ||
total: final.length, | ||
tiles: { | ||
url: String(new URL(`${config.PMTILES_URL}/tiles/${prefix}`)) | ||
}, | ||
assets | ||
assets: final | ||
}; | ||
} catch (err) { | ||
throw new Err(500, err, 'Asset List Error'); | ||
throw new Err(500, err instanceof Error ? err : new Error(String(err)), 'Asset List Error'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.