Skip to content
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

adding is public config that defaults to false #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion src/requests/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ export default class PdfGenerationRequestAdapter {
}

toPdfGenerationRequest() {
let isPublic = "false";
if (this.requestBody.hasOwnProperty("isPublic")) isPublic = this.requestBody.isPublic;
return new PdfGenerationRequest(
this.requestBody.url,
this.fileName,
this.requestBody.cookies,
this.requestBody.options
this.requestBody.options,
isPublic
);
}
}
6 changes: 3 additions & 3 deletions src/requests/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ export default class PdfGenerationRequestHandler {
async handleRequest() {
const generatedPdfFilePath = await new PdfGenerationService().generate(this.request);
console.log('PDF generated');
const pdfUrl = await new S3PdfStorageService().store(this.getPdfStorageRequest(generatedPdfFilePath));
const pdfUrl = await new S3PdfStorageService().store(this.getPdfStorageRequest(generatedPdfFilePath, this.request.isPublic));
console.log('Pdf stored on S3');
return PdfGenerationResponseAdapter.toCreated(pdfUrl);
}

getPdfStorageRequest(pdfFilePath: string) {
return new PdfStorageRequest(this.request?.fileName, pdfFilePath, {
getPdfStorageRequest(pdfFilePath: string, isPublic: boolean) {
return new PdfStorageRequest(this.request?.fileName, pdfFilePath, isPublic, {
url: this.request?.url
});
}
Expand Down
5 changes: 4 additions & 1 deletion src/requests/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ export default class PdfGenerationRequest {
cookies?: Protocol.Network.CookieParam[];
pdfOptions?: Partial<PDFOptions>;
browserOptions?: Partial<PDFRequestBrowserOptions>;
isPublic: boolean;
constructor(
url: string,
fileName: string,
cookies: Protocol.Network.CookieParam[],
options: PDFRequestOptions = { pdfOptions: {}, browserOptions: {} }
options: PDFRequestOptions = { pdfOptions: {}, browserOptions: {} },
isPublic: string
) {
this.url = url;
this.fileName = fileName;
this.cookies = cookies;
this.pdfOptions = options?.pdfOptions ?? {};
this.browserOptions = options?.browserOptions ?? {};
this.isPublic = isPublic === "true";
}
}
4 changes: 3 additions & 1 deletion src/requests/storage-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { PutObjectRequest } from '@aws-sdk/client-s3';
export default class PdfStorageRequest {
fileName: string;
filePath: string;
isPublic: boolean;
metadata: PutObjectRequest['Metadata'];
constructor(fileName: string, filePath: string, metadata: PutObjectRequest['Metadata']) {
constructor(fileName: string, filePath: string, isPublic: boolean, metadata: PutObjectRequest['Metadata']) {
this.fileName = fileName;
this.filePath = filePath;
this.isPublic = isPublic;
this.metadata = metadata;
}
}
4 changes: 3 additions & 1 deletion src/s3/requests/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import FileService from '../../services/file-service';

export default class S3PdfStorageRequestAdapter {
toPutObjectCommand(pdfStorageRequest: PdfStorageRequest) {
let isPublicString = 'no';
if (pdfStorageRequest.isPublic) isPublicString = 'yes';
return new PutObjectCommand({
Bucket: PDF_STORAGE_BUCKET_NAME,
Key: `tmp/${pdfStorageRequest.fileName}`,
Expand All @@ -14,7 +16,7 @@ export default class S3PdfStorageRequestAdapter {
ContentDisposition: 'attachment',
CacheControl: 'no-cache',
Metadata: pdfStorageRequest.metadata,
Tagging: 'public=yes'
Tagging: `public=${isPublicString}`
});
}
}