-
Notifications
You must be signed in to change notification settings - Fork 17
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(cli): allow overriding imagery names #2169
Changes from all commits
680e7dc
fe6e2c0
8585d75
21423b3
9244ffe
1291b4a
0072371
210973b
7dd60f9
d1688f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import { HttpHeader, LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda'; | ||
import { Config, fsa } from '@basemaps/shared'; | ||
import { Config, extractYearRangeFromName, fsa } from '@basemaps/shared'; | ||
import { createHash } from 'crypto'; | ||
import { findImagery, RoleRegister } from '../import/imagery.find.js'; | ||
import { Nztm2000Tms, TileMatrixSets } from '@basemaps/geo'; | ||
import { getJobCreationContext } from '../import/make.cog.js'; | ||
import { ConfigProcessingJob, JobStatus } from '@basemaps/config'; | ||
import { CogJobFactory } from '@basemaps/cli'; | ||
import * as ulid from 'ulid'; | ||
import { basename } from 'path'; | ||
|
||
/** | ||
* Trigger import imagery job by this endpoint | ||
|
@@ -17,6 +18,7 @@ import * as ulid from 'ulid'; | |
export async function Import(req: LambdaHttpRequest): Promise<LambdaHttpResponse> { | ||
const path = req.query.get('path'); | ||
const projection = req.query.get('p'); | ||
const id = ulid.ulid(); | ||
|
||
// Parse projection as target, default to process both NZTM2000Quad | ||
let targetTms = Nztm2000Tms; | ||
|
@@ -26,8 +28,18 @@ export async function Import(req: LambdaHttpRequest): Promise<LambdaHttpResponse | |
targetTms = tileMatrix; | ||
} | ||
|
||
// Find the imagery from s3 | ||
// Validate the s3 path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @blacha I added some more here, to validate the imagery name before pass it to the CogJobContext. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is going to give very weird imagery names, maybe we should just use Some of these import paths will be completely meaningless, imagine a folder There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, we cannot just add uild_year into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am going to make this imageryName as optional attributions for CogJobContext. And add this after creating hash. |
||
if (path == null || !path.startsWith('s3://')) return new LambdaHttpResponse(400, `Invalid s3 path: ${path}`); | ||
|
||
// Check if the imagery name contains a year | ||
let imageryName = basename(path); | ||
const years = extractYearRangeFromName(imageryName); | ||
if (years[0] === -1) { | ||
const year = new Date().getFullYear().toString(); | ||
imageryName = `${id}_${year}`; | ||
} | ||
|
||
// Find the imagery from s3 | ||
const role = await RoleRegister.findRole(path); | ||
if (role == null) return new LambdaHttpResponse(403, 'Unable to Access the s3 bucket'); | ||
const files = await findImagery(path); | ||
|
@@ -41,7 +53,7 @@ export async function Import(req: LambdaHttpRequest): Promise<LambdaHttpResponse | |
let jobConfig = await Config.ProcessingJob.get(jobId); | ||
if (jobConfig == null) { | ||
// Add ids into JobCreationContext | ||
const id = ulid.ulid(); | ||
ctx.imageryName = imageryName; | ||
ctx.override!.id = id; | ||
ctx.override!.processingId = jobId; | ||
ctx.outputLocation.path = fsa.join(ctx.outputLocation.path, id); | ||
|
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.
@blacha I have added this check in here. In cases, partially processed file list never get to
CogCreate:JobComplete
to create 'ts_' and 'im_' records.