Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/server/src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ export default () => ({
downloads: {
bucketPrefix: 'downloads',
jobName: process.env.ZIP_JOB_NAME
},
endpoints: {
gateway: process.env.GATEWAY_ENDPOINT || 'http://localhost:3002/graphql'
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Dataset } from '../../dataset/dataset.model';
import { DatasetPipe } from '../../dataset/pipes/dataset.pipe';
import { DatasetDownloadRequestPipe } from '../pipes/dataset-download-request.pipe';

@UseGuards(JwtAuthGuard, OrganizationGuard)
@Resolver(() => DatasetDownloadRequest)
export class DatasetDownloadRequestResolver {
constructor(
Expand All @@ -21,6 +20,7 @@ export class DatasetDownloadRequestResolver {
) {}

@Mutation(() => DatasetDownloadRequest)
@UseGuards(JwtAuthGuard, OrganizationGuard)
async createDatasetDownload(
@Args('downloadRequest', CreateDatasetDownloadPipe) downloadRequest: CreateDatasetDownloadRequest,
@OrganizationContext() organization: Organization
Expand All @@ -29,6 +29,7 @@ export class DatasetDownloadRequestResolver {
}

@Query(() => [DatasetDownloadRequest])
@UseGuards(JwtAuthGuard, OrganizationGuard)
async getDatasetDownloads(
@Args('dataset', { type: () => ID }, DatasetPipe) dataset: Dataset
): Promise<DatasetDownloadRequest[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import { StudyPipe } from '../../study/pipes/study.pipe';
import { Study } from '../../study/study.model';
import { StudyDownloadRequestPipe } from '../pipes/study-download-request.pipe';

@UseGuards(JwtAuthGuard, OrganizationGuard)
@Resolver(() => StudyDownloadRequest)
export class StudyDownloadRequestResolver {
constructor(private readonly studyDownloadService: StudyDownloadService, private readonly studyPipe: StudyPipe) {}

@Mutation(() => StudyDownloadRequest)
@UseGuards(JwtAuthGuard, OrganizationGuard)
async createStudyDownload(
@Args('downloadRequest', CreateStudyDownloadPipe) downloadRequest: CreateStudyDownloadRequest,
@OrganizationContext() organization: Organization
Expand All @@ -26,6 +26,7 @@ export class StudyDownloadRequestResolver {
}

@Query(() => [StudyDownloadRequest])
@UseGuards(JwtAuthGuard, OrganizationGuard)
async getStudyDownloads(@Args('study', { type: () => ID }, StudyPipe) study: Study): Promise<StudyDownloadRequest[]> {
return this.studyDownloadService.getStudyDownloads(study);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ import { randomUUID } from 'crypto';
@Injectable()
export class DatasetDownloadService {
private readonly expiration = this.configService.getOrThrow<number>('entry.signedURLExpiration');
private readonly gatewayEndpoint = this.configService.getOrThrow<string>('endpoints.gateway');

/** The mutation to execute for marking a field as complete */
private readonly markCompleteMutation = `
mutation markDatasetFieldComplete($downloadRequest: ID!, $datasetField: DatasetDownloadField!, $code: String!) {
markDatasetFieldComplete(downloadRequest: $downloadRequest, datasetField: $datasetField, code: $code)
}
`;

constructor(
@InjectModel(DatasetDownloadRequest.name)
Expand Down Expand Up @@ -64,8 +72,15 @@ export class DatasetDownloadService {
entryJSONLocation: request.entryJSONLocation!,
entryZIPLocation: request.entryZIPLocation!,
webhookPayloadLocation: request.webhookPayloadLocation!,
webhookPayload: JSON.stringify({ test: 'hello' }),
webhook: 'http://localhost:3000/',
webhookPayload: JSON.stringify({
query: this.markCompleteMutation,
variables: {
downloadRequest: request._id,
datasetField: DatasetDownloadField.ENTRY_ZIP.toString(),
code: request.verificationCode
}
}),
webhook: this.gatewayEndpoint,
entries: await this.entryService.findForDataset(request.dataset),
bucket: (await this.bucketFactory.getBucket(request.organization))!,
organization: request.organization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class DownloadRequestService {
args: [
`--target_entries=${mountPoint}/${request.entryJSONLocation}`,
`--output_zip=${mountPoint}/${request.entryZIPLocation}`,
`--notification_webhook=http://localhost:3000`,
`--notification_webhook=${request.webhook}`,
`--webhook_payload=${mountPoint}/${request.webhookPayloadLocation}`
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ import { randomUUID } from 'crypto';
@Injectable()
export class StudyDownloadService {
private readonly expiration = this.configService.getOrThrow<number>('entry.signedURLExpiration');
private readonly gatewayEndpoint = this.configService.getOrThrow<string>('endpoints.gateway');

/** The mutation to execute for marking a field as complete */
private readonly markCompleteMutation = `
mutation markStudyFieldComplete($downloadRequest: ID!, $studyField: StudyDownloadField!, $code: String!) {
markStudyFieldComplete(downloadRequest: $downloadRequest, studyField: $studyField, code: $code)
}
`;

constructor(
@InjectModel(StudyDownloadRequest.name)
Expand Down Expand Up @@ -79,8 +87,15 @@ export class StudyDownloadService {
entryJSONLocation: request.entryJSONLocation!,
entryZIPLocation: request.entryZIPLocation!,
webhookPayloadLocation: request.webhookPayloadLocation!,
webhookPayload: JSON.stringify({ test: 'hello' }),
webhook: 'http://localhost:3000',
webhookPayload: JSON.stringify({
query: this.markCompleteMutation,
variables: {
downloadRequest: request._id,
studyField: StudyDownloadField.ENTRY_ZIP.toString(),
code: request.verificationCode
}
}),
webhook: this.gatewayEndpoint,
entries: await this.entryService.getEntriesForStudy(request.study),
bucket: (await this.bucketFactory.getBucket(request.organization))!,
organization: request.organization
Expand All @@ -92,8 +107,15 @@ export class StudyDownloadService {
entryJSONLocation: request.taggedEntriesJSONLocation!,
entryZIPLocation: request.taggedEntriesZipLocation!,
webhookPayloadLocation: request.taggedEntryWebhookPayloadLocation!,
webhookPayload: JSON.stringify({ test: 'hello' }),
webhook: 'http://localhost:3000',
webhookPayload: JSON.stringify({
query: this.markCompleteMutation,
variables: {
downloadRequest: request._id,
studyField: StudyDownloadField.TAGGED_ENTRIES_ZIP.toString(),
code: request.verificationCode
}
}),
webhook: this.gatewayEndpoint,
entries: await this.getLabeledEntries(request),
bucket: (await this.bucketFactory.getBucket(request.organization))!,
organization: request.organization
Expand Down
18 changes: 14 additions & 4 deletions packages/zipper/src/commands/zip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class ZipHander extends Command {
const entries: string[] = JSON.parse(await readFile(flags.target_entries, 'utf8'))['entries'];

// Load the webhook payload (before taking too long with zipping)
// const payload = await readFile(flags.webhook_payload, 'utf8');
const payload = await readFile(flags.webhook_payload, 'utf8');

// Add the enties to the zip
for (const entry of entries) {
Expand All @@ -43,11 +43,21 @@ export default class ZipHander extends Command {
await zip.writeZipPromise(flags.output_zip);

// Post to the webhook to notify of completion
/*
await fetch(flags.notification_webhook, {
const result = await fetch(flags.notification_webhook, {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: payload
});
*/

// Check to make sure the request went through successfully
if (result.status != 200) {
console.error(await result.text());
throw new Error('Failed to call webhook');
}

// Left for easier debugging
console.log(await result.json());
}
}