diff --git a/package.json b/package.json index 6c6c9714..8061d179 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "google-spreadsheet": "3.3.0", "lock": "1.1.0", "node-cron": "3.0.3", + "node-fetch": "^3.3.2", "tsup": "8.1.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 62684a4b..b4b95798 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,6 +29,9 @@ importers: node-cron: specifier: 3.0.3 version: 3.0.3 + node-fetch: + specifier: ^3.3.2 + version: 3.3.2 tsup: specifier: 8.1.0 version: 8.1.0(ts-node@10.9.2)(typescript@5.4.5) @@ -3406,6 +3409,11 @@ packages: resolution: {integrity: sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==} dev: true + /data-uri-to-buffer@4.0.1: + resolution: {integrity: sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==} + engines: {node: '>= 12'} + dev: false + /data-view-buffer@1.0.1: resolution: {integrity: sha512-0lht7OugA5x3iJLOWFhWK/5ehONdprk0ISXqVFn/NFrDu+cuc8iADFrGQz5BnRK7LLU3JmkbXSxaqX+/mXYtUA==} engines: {node: '>= 0.4'} @@ -3997,6 +4005,14 @@ packages: bser: 2.1.1 dev: true + /fetch-blob@3.2.0: + resolution: {integrity: sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==} + engines: {node: ^12.20 || >= 14.13} + dependencies: + node-domexception: 1.0.0 + web-streams-polyfill: 3.3.3 + dev: false + /file-entry-cache@6.0.1: resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==} engines: {node: ^10.12.0 || >=12.0.0} @@ -4100,6 +4116,13 @@ packages: mime-types: 2.1.35 dev: false + /formdata-polyfill@4.0.10: + resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==} + engines: {node: '>=12.20.0'} + dependencies: + fetch-blob: 3.2.0 + dev: false + /forwarded@0.2.0: resolution: {integrity: sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==} engines: {node: '>= 0.6'} @@ -5566,6 +5589,11 @@ packages: uuid: 8.3.2 dev: false + /node-domexception@1.0.0: + resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==} + engines: {node: '>=10.5.0'} + dev: false + /node-fetch@2.7.0: resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==} engines: {node: 4.x || >=6.0.0} @@ -5578,6 +5606,15 @@ packages: whatwg-url: 5.0.0 dev: false + /node-fetch@3.3.2: + resolution: {integrity: sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + data-uri-to-buffer: 4.0.1 + fetch-blob: 3.2.0 + formdata-polyfill: 4.0.10 + dev: false + /node-forge@1.3.1: resolution: {integrity: sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==} engines: {node: '>= 6.13.0'} @@ -6707,6 +6744,11 @@ packages: makeerror: 1.0.12 dev: true + /web-streams-polyfill@3.3.3: + resolution: {integrity: sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==} + engines: {node: '>= 8'} + dev: false + /webidl-conversions@3.0.1: resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} dev: false diff --git a/src/bot/requestReview.ts b/src/bot/requestReview.ts index cd774a21..7591468f 100644 --- a/src/bot/requestReview.ts +++ b/src/bot/requestReview.ts @@ -110,20 +110,20 @@ export const requestReview = { }, }, }, - // { - // type: 'input', - // block_id: ActionId.PDF_IDENTIFIER, - // label: { - // text: 'Input PDF File', - // type: 'plain_text', - // }, - // element: { - // type: 'file_input', - // action_id: ActionId.PDF_IDENTIFIER, - // max_files: 1, - // filetypes: ['pdf'], - // }, - // }, + { + type: 'input', + block_id: ActionId.PDF_IDENTIFIER, + label: { + text: 'Input PDF File', + type: 'plain_text', + }, + element: { + type: 'file_input', + action_id: ActionId.PDF_IDENTIFIER, + max_files: 1, + filetypes: ['pdf'], + }, + }, ], submit: { type: 'plain_text', @@ -172,13 +172,21 @@ export const requestReview = { const candidateIdentifier = blockUtils.getBlockValue(body, ActionId.CANDIDATE_IDENTIFIER); const reviewType = blockUtils.getBlockValue(body, ActionId.REVIEW_TYPE).selected_option.text .text; - // const pdf = blockUtils.getBlockValue(body, ActionId.PDF_IDENTIFIER); - // log.d(pdf); + const fileInput = blockUtils.getBlockValue(body, ActionId.PDF_IDENTIFIER); + const pdf = fileInput.files[0]; + const pdfIdentifier = pdf.name; + const pdfDownloadUrl = pdf.url_private_download; + + const pdfBuffer = await new Promise(resolve => { + fetch(pdfDownloadUrl) + .then(res => res.arrayBuffer()) + .then(buffer => { + return resolve(buffer); + }); + }); // Upload PDF to S3 here. - const pdfIdentifier = 'Report_Tech_Trials__Auth___Analysis_bskiff_sourceallies.com.pdf'; - const pdf = Buffer.from('test file should be here not this'); - await putPdfToS3(pdfIdentifier, pdf); + await putPdfToS3(pdfIdentifier, pdfBuffer); const numberOfReviewersValue = numberOfReviewers.value; const deadlineValue = deadline.selected_option.value;