@basemaps/lambda-tiler 6.25.0 → 6.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/build/{__test__ → __tests__}/index.test.d.ts +0 -0
  3. package/build/{__test__ → __tests__}/index.test.d.ts.map +1 -1
  4. package/build/{__test__ → __tests__}/index.test.js +0 -0
  5. package/build/{__test__ → __tests__}/route.test.d.ts +0 -0
  6. package/build/{__test__ → __tests__}/route.test.d.ts.map +1 -1
  7. package/build/{__test__ → __tests__}/route.test.js +0 -0
  8. package/build/{__test__ → __tests__}/tiff.cache.test.d.ts +0 -0
  9. package/build/__tests__/tiff.cache.test.d.ts.map +1 -0
  10. package/build/{__test__ → __tests__}/tiff.cache.test.js +0 -0
  11. package/build/{__test__ → __tests__}/tile.cache.key.test.d.ts +0 -0
  12. package/build/__tests__/tile.cache.key.test.d.ts.map +1 -0
  13. package/build/{__test__ → __tests__}/tile.cache.key.test.js +0 -0
  14. package/build/{__test__ → __tests__}/tile.set.cache.test.d.ts +0 -0
  15. package/build/__tests__/tile.set.cache.test.d.ts.map +1 -0
  16. package/build/{__test__ → __tests__}/tile.set.cache.test.js +0 -0
  17. package/build/{__test__ → __tests__}/tile.set.test.d.ts +0 -0
  18. package/build/__tests__/tile.set.test.d.ts.map +1 -0
  19. package/build/{__test__ → __tests__}/tile.set.test.js +0 -5
  20. package/build/{__test__ → __tests__}/tile.style.json.test.d.ts +0 -0
  21. package/build/__tests__/tile.style.json.test.d.ts.map +1 -0
  22. package/build/{__test__ → __tests__}/tile.style.json.test.js +0 -0
  23. package/build/{__test__ → __tests__}/wmts.capability.test.d.ts +0 -0
  24. package/build/__tests__/wmts.capability.test.d.ts.map +1 -0
  25. package/build/{__test__ → __tests__}/wmts.capability.test.js +36 -9
  26. package/build/{__test__ → __tests__}/xyz.test.d.ts +0 -0
  27. package/build/{__test__ → __tests__}/xyz.test.d.ts.map +1 -1
  28. package/build/{__test__ → __tests__}/xyz.test.js +0 -4
  29. package/build/{__test__ → __tests__}/xyz.util.d.ts +0 -0
  30. package/build/__tests__/xyz.util.d.ts.map +1 -0
  31. package/build/{__test__ → __tests__}/xyz.util.js +0 -0
  32. package/build/index.d.ts +3 -1
  33. package/build/index.d.ts.map +1 -1
  34. package/build/index.js +2 -3
  35. package/build/routes/{__test__ → __tests__}/attribution.test.d.ts +0 -0
  36. package/build/routes/__tests__/attribution.test.d.ts.map +1 -0
  37. package/build/routes/{__test__ → __tests__}/attribution.test.js +3 -2
  38. package/build/routes/{__test__ → __tests__}/health.test.d.ts +0 -0
  39. package/build/routes/__tests__/health.test.d.ts.map +1 -0
  40. package/build/routes/{__test__ → __tests__}/health.test.js +0 -0
  41. package/build/routes/{__test__ → __tests__}/imagery.test.d.ts +0 -0
  42. package/build/routes/__tests__/imagery.test.d.ts.map +1 -0
  43. package/build/routes/{__test__ → __tests__}/imagery.test.js +0 -0
  44. package/build/routes/__tests__/wmts.test.d.ts +2 -0
  45. package/build/routes/__tests__/wmts.test.d.ts.map +1 -0
  46. package/build/routes/__tests__/wmts.test.js +31 -0
  47. package/build/routes/tile.json.js +1 -1
  48. package/build/routes/tile.wmts.d.ts +2 -0
  49. package/build/routes/tile.wmts.d.ts.map +1 -1
  50. package/build/routes/tile.wmts.js +23 -3
  51. package/build/tile.set.cache.js +1 -1
  52. package/build/tile.set.raster.d.ts +1 -6
  53. package/build/tile.set.raster.d.ts.map +1 -1
  54. package/build/tile.set.raster.js +12 -22
  55. package/build/tile.set.vector.d.ts.map +1 -1
  56. package/build/tile.set.vector.js +3 -1
  57. package/build/wmts.capability.d.ts +12 -6
  58. package/build/wmts.capability.d.ts.map +1 -1
  59. package/build/wmts.capability.js +12 -11
  60. package/package.json +13 -14
  61. package/scripts/create.deployment.package.mjs +3 -3
  62. package/src/{__test__ → __tests__}/index.test.ts +0 -0
  63. package/src/{__test__ → __tests__}/route.test.ts +0 -0
  64. package/src/{__test__ → __tests__}/tiff.cache.test.ts +0 -0
  65. package/src/{__test__ → __tests__}/tile.cache.key.test.ts +0 -0
  66. package/src/{__test__ → __tests__}/tile.set.cache.test.ts +0 -0
  67. package/src/{__test__ → __tests__}/tile.set.test.ts +0 -7
  68. package/src/{__test__ → __tests__}/tile.style.json.test.ts +0 -0
  69. package/src/{__test__ → __tests__}/wmts.capability.test.ts +39 -8
  70. package/src/{__test__ → __tests__}/xyz.test.ts +0 -4
  71. package/src/{__test__ → __tests__}/xyz.util.ts +0 -0
  72. package/src/index.ts +2 -3
  73. package/src/routes/{__test__ → __tests__}/attribution.test.ts +3 -2
  74. package/src/routes/{__test__ → __tests__}/health.test.ts +0 -0
  75. package/src/routes/{__test__ → __tests__}/imagery.test.ts +0 -0
  76. package/src/routes/__tests__/wmts.test.ts +40 -0
  77. package/src/routes/tile.json.ts +1 -1
  78. package/src/routes/tile.wmts.ts +23 -3
  79. package/src/tile.set.cache.ts +1 -1
  80. package/src/tile.set.raster.ts +12 -21
  81. package/src/tile.set.vector.ts +2 -1
  82. package/src/wmts.capability.ts +21 -15
  83. package/tsconfig.tsbuildinfo +1 -1
  84. package/build/__test__/tiff.cache.test.d.ts.map +0 -1
  85. package/build/__test__/tile.cache.key.test.d.ts.map +0 -1
  86. package/build/__test__/tile.import.test.d.ts +0 -2
  87. package/build/__test__/tile.import.test.d.ts.map +0 -1
  88. package/build/__test__/tile.import.test.js +0 -115
  89. package/build/__test__/tile.set.cache.test.d.ts.map +0 -1
  90. package/build/__test__/tile.set.test.d.ts.map +0 -1
  91. package/build/__test__/tile.style.json.test.d.ts.map +0 -1
  92. package/build/__test__/wmts.capability.test.d.ts.map +0 -1
  93. package/build/__test__/xyz.util.d.ts.map +0 -1
  94. package/build/import/imagery.find.d.ts +0 -17
  95. package/build/import/imagery.find.d.ts.map +0 -1
  96. package/build/import/imagery.find.js +0 -38
  97. package/build/import/make.cog.d.ts +0 -5
  98. package/build/import/make.cog.d.ts.map +0 -1
  99. package/build/import/make.cog.js +0 -21
  100. package/build/routes/__test__/attribution.test.d.ts.map +0 -1
  101. package/build/routes/__test__/health.test.d.ts.map +0 -1
  102. package/build/routes/__test__/imagery.test.d.ts.map +0 -1
  103. package/build/routes/import.d.ts +0 -9
  104. package/build/routes/import.d.ts.map +0 -1
  105. package/build/routes/import.js +0 -61
  106. package/src/__test__/tile.import.test.ts +0 -140
  107. package/src/import/imagery.find.ts +0 -60
  108. package/src/import/make.cog.ts +0 -29
  109. package/src/routes/import.ts +0 -66
@@ -1,5 +0,0 @@
1
- import { JobCreationContext } from '@basemaps/cli/build/cog/cog.stac.job';
2
- import { TileMatrixSet } from '@basemaps/geo';
3
- import { RoleConfig } from './imagery.find.js';
4
- export declare function getJobCreationContext(path: string, tileMatrix: TileMatrixSet, role: RoleConfig, files: string[]): Promise<JobCreationContext>;
5
- //# sourceMappingURL=make.cog.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"make.cog.d.ts","sourceRoot":"","sources":["../../src/import/make.cog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,aAAa,EACzB,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,EAAE,GACd,OAAO,CAAC,kBAAkB,CAAC,CAkB7B"}
@@ -1,21 +0,0 @@
1
- import { Env } from '@basemaps/shared';
2
- export async function getJobCreationContext(path, tileMatrix, role, files) {
3
- const bucket = Env.get(Env.ImportImageryBucket);
4
- if (bucket == null)
5
- throw new Error('Output AWS s3 bucket Not Found.');
6
- const ctx = {
7
- override: {
8
- projection: tileMatrix.projection,
9
- resampling: {
10
- warp: 'bilinear',
11
- overview: 'lanczos',
12
- },
13
- },
14
- outputLocation: { type: 's3', path: `s3://${bucket}` },
15
- sourceLocation: { type: 's3', path, ...role, files: files },
16
- batch: true,
17
- tileMatrix,
18
- oneCogCovering: false,
19
- };
20
- return ctx;
21
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"attribution.test.d.ts","sourceRoot":"","sources":["../../../src/routes/__test__/attribution.test.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"health.test.d.ts","sourceRoot":"","sources":["../../../src/routes/__test__/health.test.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"imagery.test.d.ts","sourceRoot":"","sources":["../../../src/routes/__test__/imagery.test.ts"],"names":[],"mappings":""}
@@ -1,9 +0,0 @@
1
- import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
2
- /**
3
- * Trigger import imagery job by this endpoint
4
- *
5
- * @example
6
- * - /v1/import?path=s3://linz-imagery-staging/2022-03/wellington_rural_2022_delivery_1
7
- */
8
- export declare function Import(req: LambdaHttpRequest): Promise<LambdaHttpResponse>;
9
- //# sourceMappingURL=import.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"import.d.ts","sourceRoot":"","sources":["../../src/routes/import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AASnF;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAkDhF"}
@@ -1,61 +0,0 @@
1
- import { HttpHeader, LambdaHttpResponse } from '@linzjs/lambda';
2
- import { Config, Const, fsa } from '@basemaps/shared';
3
- import { createHash } from 'crypto';
4
- import { findImagery, RoleRegister } from '../import/imagery.find.js';
5
- import { Nztm2000Tms, TileMatrixSets } from '@basemaps/geo';
6
- import { getJobCreationContext } from '../import/make.cog.js';
7
- import { ConfigProviderDynamo } from '@basemaps/config';
8
- import { CogJobFactory } from '@basemaps/cli';
9
- /**
10
- * Trigger import imagery job by this endpoint
11
- *
12
- * @example
13
- * - /v1/import?path=s3://linz-imagery-staging/2022-03/wellington_rural_2022_delivery_1
14
- */
15
- export async function Import(req) {
16
- const path = req.query.get('path');
17
- const projection = req.query.get('p');
18
- // Parse projection as target, default to process both NZTM2000Quad
19
- let targetTms = Nztm2000Tms;
20
- if (projection != null) {
21
- const tileMatrix = TileMatrixSets.find(projection);
22
- if (tileMatrix == null)
23
- return new LambdaHttpResponse(404, 'Target projection Not found');
24
- targetTms = tileMatrix;
25
- }
26
- // Find the imagery from s3
27
- if (path == null || !path.startsWith('s3://'))
28
- return new LambdaHttpResponse(500, 'Invalid s3 path');
29
- const role = await RoleRegister.findRole(path);
30
- if (role == null)
31
- return new LambdaHttpResponse(500, 'Unable to Access the bucket');
32
- const files = await findImagery(path);
33
- if (files.length === 0)
34
- return new LambdaHttpResponse(404, 'Imagery Not Found');
35
- // Prepare Cog jobs
36
- const ctx = await getJobCreationContext(path, targetTms, role, files);
37
- const id = createHash('sha256').update(JSON.stringify(ctx)).digest('base64');
38
- const jobId = Config.ProcessingJob.id(id);
39
- let jobConfig = await Config.ProcessingJob.get(jobId);
40
- if (jobConfig == null) {
41
- // Add id back to JobCreationContext
42
- ctx.override.id = id;
43
- ctx.outputLocation.path = fsa.join(ctx.outputLocation.path, id);
44
- // Start processing job
45
- await CogJobFactory.create(ctx);
46
- jobConfig = {
47
- id: jobId,
48
- name: path,
49
- status: 'processing',
50
- };
51
- const config = new ConfigProviderDynamo(Const.TileMetadata.TableName);
52
- await config.ProcessingJob.put(jobConfig);
53
- }
54
- const json = JSON.stringify(jobConfig);
55
- const data = Buffer.from(json);
56
- const response = new LambdaHttpResponse(200, 'ok');
57
- response.header(HttpHeader.CacheControl, 'no-store');
58
- response.buffer(data, 'application/json');
59
- req.set('bytes', data.byteLength);
60
- return response;
61
- }
@@ -1,140 +0,0 @@
1
- import { JobCreationContext } from '@basemaps/cli/build/cog/cog.stac.job';
2
- import { Nztm2000Tms } from '@basemaps/geo';
3
- import { Config, Env, fsa, LogConfig } from '@basemaps/shared';
4
- import o from 'ospec';
5
- import { createHash } from 'crypto';
6
- import sinon from 'sinon';
7
- import { LambdaAlbRequest, LambdaHttpRequest } from '@linzjs/lambda';
8
- import { Context } from 'aws-lambda';
9
- import { Import } from '../routes/import.js';
10
- import { RoleConfig } from '../import/imagery.find.js';
11
- import { CogJobFactory } from '@basemaps/cli';
12
- import { ConfigProcessingJob } from '@basemaps/config';
13
-
14
- o.spec('Import', () => {
15
- const sandbox = sinon.createSandbox();
16
- const outputBucket = 'testOutputBucket';
17
- const configBucket = 'testConfigBucket';
18
- const origConfigBucket = process.env[Env.AwsRoleConfigBucket];
19
- const origOutputBucket = process.env[Env.ImportImageryBucket];
20
- o.beforeEach(() => {
21
- process.env[Env.AwsRoleConfigBucket] = configBucket;
22
- process.env[Env.ImportImageryBucket] = outputBucket;
23
- });
24
-
25
- o.afterEach(() => {
26
- process.env[Env.AwsRoleConfigBucket] = origConfigBucket;
27
- process.env[Env.ImportImageryBucket] = origOutputBucket;
28
- sandbox.restore();
29
- });
30
-
31
- const tileMatrix = Nztm2000Tms;
32
- const bucket = 'testSourceBucket';
33
- const path = `s3://${bucket}/imagery/`;
34
- const role: RoleConfig = {
35
- bucket,
36
- accountId: '123456',
37
- roleArn: 'arn:aws:iam::123456:role/read-role',
38
- };
39
-
40
- const files = [`${path}/1.tiff`, `${path}/2.tiff`];
41
- async function* listFiles(): AsyncGenerator<string, any, unknown> {
42
- for (const key in files) yield files[key];
43
- }
44
-
45
- const ctx: JobCreationContext = {
46
- override: {
47
- projection: tileMatrix.projection,
48
- resampling: {
49
- warp: 'bilinear',
50
- overview: 'lanczos',
51
- },
52
- },
53
- outputLocation: { type: 's3' as const, path: `s3://${outputBucket}` },
54
- sourceLocation: { type: 's3', path: path, ...role, files: files },
55
- batch: true,
56
- tileMatrix,
57
- oneCogCovering: false,
58
- };
59
-
60
- const id = createHash('sha256').update(JSON.stringify(ctx)).digest('base64');
61
- const jobId = Config.ProcessingJob.id(id);
62
-
63
- function getRequest(path: string, projection: string): LambdaHttpRequest {
64
- return new LambdaAlbRequest(
65
- {
66
- requestContext: null as any,
67
- httpMethod: 'get',
68
- path: '/v1/tiles/import',
69
- body: null,
70
- isBase64Encoded: false,
71
- queryStringParameters: { path: path, p: projection },
72
- },
73
- {} as Context,
74
- LogConfig.get(),
75
- );
76
- }
77
-
78
- o('should return projection not found', async () => {
79
- // Given ... wrong projection
80
- const req = getRequest(path, '0000');
81
-
82
- // When ... Then ...
83
- const res = await Import(req);
84
- o(res.body).equals('{"status":404,"message":"Target projection Not found"}');
85
- });
86
-
87
- o('should return Invalid s3 location', async () => {
88
- // Given... wrong s3 path
89
- const req = getRequest('s3::testbucket/', '2193');
90
-
91
- // When ...Then ...
92
- const res = await Import(req);
93
- o(res.body).equals('{"status":500,"message":"Invalid s3 path"}');
94
- });
95
-
96
- o('should return Unable to access bucket', async () => {
97
- // Given... different bucket have no access role
98
- sandbox.stub(fsa, 'readJson').resolves({ buckets: [role] });
99
- const req = getRequest(`s3://wrong-bucket/imagery/`, '2193');
100
-
101
- // When ...Then ...
102
- const res = await Import(req);
103
- o(res.body).equals('{"status":500,"message":"Unable to Access the bucket"}');
104
- });
105
-
106
- o('should return Imagery not found', async () => {
107
- // Given... none imagery find from bucket
108
- sandbox.stub(fsa, 'readJson').resolves({ buckets: [role] });
109
- sandbox.stub(fsa, 'list').callsFake(async function* () {
110
- yield `${path}1.json`;
111
- });
112
-
113
- const req = getRequest(path, '2193');
114
-
115
- // When ...Then ...
116
- const res = await Import(req);
117
- o(res.body).equals('{"status":404,"message":"Imagery Not Found"}');
118
- });
119
-
120
- o('should return 200 with existing import', async () => {
121
- // Given... different bucket have no access role
122
- sandbox.stub(fsa, 'readJson').resolves({ buckets: [role] });
123
- sandbox.stub(fsa, 'list').callsFake(listFiles);
124
- sandbox.stub(CogJobFactory, 'create').resolves(undefined);
125
-
126
- const jobConfig = {
127
- id: jobId,
128
- name: path,
129
- status: 'complete',
130
- } as ConfigProcessingJob;
131
- sandbox.stub(Config.ProcessingJob, 'get').resolves(jobConfig);
132
- const req = getRequest(path, '2193');
133
-
134
- // When ...Then ...
135
- const res = await Import(req);
136
- o(res.status).equals(200);
137
- const body = Buffer.from(res.body ?? '', 'base64').toString();
138
- o(JSON.parse(body)).deepEquals(jobConfig);
139
- });
140
- });
@@ -1,60 +0,0 @@
1
- import { AwsCredentials } from '@chunkd/source-aws-v2';
2
- import { fsa } from '@chunkd/fs';
3
- import { Env } from '@basemaps/shared';
4
-
5
- export interface RoleConfig {
6
- bucket: string;
7
- accountId: string;
8
- roleArn: string;
9
- externalId?: string;
10
- roleSessionDuration?: number;
11
- }
12
-
13
- interface BucketConfig {
14
- v: number;
15
- buckets: RoleConfig[];
16
- version: string;
17
- package: string;
18
- hash: string;
19
- updatedAt: string;
20
- }
21
-
22
- export class RoleRegister {
23
- /** Get all imagery source aws roles */
24
- static async _loadRoles(): Promise<RoleConfig[]> {
25
- const configBucket = Env.get(Env.AwsRoleConfigBucket);
26
- if (configBucket == null) return [];
27
- const configPath = `s3://${configBucket}/config.json`;
28
- const config: BucketConfig = await fsa.readJson(configPath);
29
- const roles = [];
30
- for (const role of config.buckets) {
31
- fsa.register(
32
- 's3://' + role.bucket,
33
- AwsCredentials.fsFromRole(role.roleArn, role.externalId, role.roleSessionDuration),
34
- );
35
- roles.push(role);
36
- }
37
- return roles;
38
- }
39
-
40
- static _loadRolesPromise: Promise<RoleConfig[]> | undefined;
41
- static loadRoles(): Promise<RoleConfig[]> {
42
- if (RoleRegister._loadRolesPromise == null) RoleRegister._loadRolesPromise = this._loadRoles();
43
- return RoleRegister._loadRolesPromise;
44
- }
45
-
46
- static async findRole(path: string): Promise<RoleConfig | undefined> {
47
- const roles = await this.loadRoles();
48
- return roles.find((f) => path.startsWith(`s3://${f.bucket}`));
49
- }
50
- }
51
-
52
- /** Search for the imagery across all of our buckets */
53
- export async function findImagery(path: string): Promise<string[]> {
54
- const files: string[] = [];
55
- for await (const key of fsa.list(path)) {
56
- const searchKey = key.toLowerCase();
57
- if (searchKey.endsWith('.tif') || searchKey.endsWith('.tiff')) files.push(key);
58
- }
59
- return files;
60
- }
@@ -1,29 +0,0 @@
1
- import { JobCreationContext } from '@basemaps/cli/build/cog/cog.stac.job';
2
- import { TileMatrixSet } from '@basemaps/geo';
3
- import { Env } from '@basemaps/shared';
4
- import { RoleConfig } from './imagery.find.js';
5
-
6
- export async function getJobCreationContext(
7
- path: string,
8
- tileMatrix: TileMatrixSet,
9
- role: RoleConfig,
10
- files: string[],
11
- ): Promise<JobCreationContext> {
12
- const bucket = Env.get(Env.ImportImageryBucket);
13
- if (bucket == null) throw new Error('Output AWS s3 bucket Not Found.');
14
- const ctx: JobCreationContext = {
15
- override: {
16
- projection: tileMatrix.projection,
17
- resampling: {
18
- warp: 'bilinear',
19
- overview: 'lanczos',
20
- },
21
- },
22
- outputLocation: { type: 's3' as const, path: `s3://${bucket}` },
23
- sourceLocation: { type: 's3', path, ...role, files: files },
24
- batch: true,
25
- tileMatrix,
26
- oneCogCovering: false,
27
- };
28
- return ctx;
29
- }
@@ -1,66 +0,0 @@
1
- import { HttpHeader, LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
2
- import { Config, Const, fsa } from '@basemaps/shared';
3
- import { createHash } from 'crypto';
4
- import { findImagery, RoleRegister } from '../import/imagery.find.js';
5
- import { Nztm2000Tms, TileMatrixSets } from '@basemaps/geo';
6
- import { getJobCreationContext } from '../import/make.cog.js';
7
- import { ConfigProcessingJob, ConfigProviderDynamo } from '@basemaps/config';
8
- import { CogJobFactory } from '@basemaps/cli';
9
-
10
- /**
11
- * Trigger import imagery job by this endpoint
12
- *
13
- * @example
14
- * - /v1/import?path=s3://linz-imagery-staging/2022-03/wellington_rural_2022_delivery_1
15
- */
16
- export async function Import(req: LambdaHttpRequest): Promise<LambdaHttpResponse> {
17
- const path = req.query.get('path');
18
- const projection = req.query.get('p');
19
-
20
- // Parse projection as target, default to process both NZTM2000Quad
21
- let targetTms = Nztm2000Tms;
22
- if (projection != null) {
23
- const tileMatrix = TileMatrixSets.find(projection);
24
- if (tileMatrix == null) return new LambdaHttpResponse(404, 'Target projection Not found');
25
- targetTms = tileMatrix;
26
- }
27
-
28
- // Find the imagery from s3
29
- if (path == null || !path.startsWith('s3://')) return new LambdaHttpResponse(500, 'Invalid s3 path');
30
- const role = await RoleRegister.findRole(path);
31
- if (role == null) return new LambdaHttpResponse(500, 'Unable to Access the bucket');
32
- const files = await findImagery(path);
33
- if (files.length === 0) return new LambdaHttpResponse(404, 'Imagery Not Found');
34
-
35
- // Prepare Cog jobs
36
- const ctx = await getJobCreationContext(path, targetTms, role, files);
37
-
38
- const id = createHash('sha256').update(JSON.stringify(ctx)).digest('base64');
39
- const jobId = Config.ProcessingJob.id(id);
40
- let jobConfig = await Config.ProcessingJob.get(jobId);
41
- if (jobConfig == null) {
42
- // Add id back to JobCreationContext
43
- ctx.override!.id = id;
44
- ctx.outputLocation.path = fsa.join(ctx.outputLocation.path, id);
45
-
46
- // Start processing job
47
- await CogJobFactory.create(ctx);
48
- jobConfig = {
49
- id: jobId,
50
- name: path,
51
- status: 'processing',
52
- } as ConfigProcessingJob;
53
-
54
- const config = new ConfigProviderDynamo(Const.TileMetadata.TableName);
55
- await config.ProcessingJob.put(jobConfig);
56
- }
57
-
58
- const json = JSON.stringify(jobConfig);
59
- const data = Buffer.from(json);
60
-
61
- const response = new LambdaHttpResponse(200, 'ok');
62
- response.header(HttpHeader.CacheControl, 'no-store');
63
- response.buffer(data, 'application/json');
64
- req.set('bytes', data.byteLength);
65
- return response;
66
- }