Skip to content

Commit

Permalink
Conver UInt8Array to Buffer to avoid being treated as a JSON response
Browse files Browse the repository at this point in the history
  • Loading branch information
jihchi committed Aug 17, 2024
1 parent 6d0682b commit 03e6750
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/views/img.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const img = async (ctx, page, size) => {

// dynamically set media type
ctx.type = `image/${type}`;
ctx.body = image;
ctx.body = Buffer.from(image);
};

module.exports = renderImgOrSvg(img);
2 changes: 1 addition & 1 deletion src/views/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const pdf = async (ctx, page, size) => {
debug('printed to pdf, file size: %o', pdf.length);

ctx.type = 'application/pdf';
ctx.body = pdf;
ctx.body = Buffer.from(pdf);
};

module.exports = renderImgOrSvg(pdf);
4 changes: 2 additions & 2 deletions test/kitchensink.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ describe('app', () => {
);
expect(resp.status).toEqual(200);
expect(resp.type).toEqual('application/pdf');
expect(resp.body.length).toBeGreaterThan(19 * KB);
expect(resp.body.length).toBeGreaterThan(17 * KB);

await PDFDocument.load(resp.body.toString('base64'));
});
Expand All @@ -417,7 +417,7 @@ describe('app', () => {
);
expect(resp.status).toEqual(200);
expect(resp.type).toEqual('application/pdf');
expect(resp.body.length).toBeGreaterThan(19 * KB);
expect(resp.body.length).toBeGreaterThan(17 * KB);

const pdfDoc = await PDFDocument.load(resp.body.toString('base64'));
const pages = pdfDoc.getPages();
Expand Down

0 comments on commit 03e6750

Please sign in to comment.