mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-13 08:13:49 +10:00
- implement donation link, in about section
This commit is contained in:
@ -7,29 +7,38 @@ function timeout(ms) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
exports.printSinglePageResume = functions.https.onCall(
|
||||
async ({ id }, { auth }) => {
|
||||
if (!id) {
|
||||
throw new functions.https.HttpsError(
|
||||
'invalid-argument',
|
||||
'The function must be called with one arguments "id" containing the resume ID.',
|
||||
);
|
||||
}
|
||||
exports.printResume = functions.https.onCall(async ({ id, type }, { auth }) => {
|
||||
if (!id) {
|
||||
throw new functions.https.HttpsError(
|
||||
'invalid-argument',
|
||||
'The function must be called with argument "id" containing the resume ID.',
|
||||
);
|
||||
}
|
||||
|
||||
if (!auth) {
|
||||
throw new functions.https.HttpsError(
|
||||
'failed-precondition',
|
||||
'The function must be called while authenticated.',
|
||||
);
|
||||
}
|
||||
if (!type || type !== 'single' || type !== 'multi') {
|
||||
throw new functions.https.HttpsError(
|
||||
'invalid-argument',
|
||||
'The function must be called with argument "type" containing the type of resume.',
|
||||
);
|
||||
}
|
||||
|
||||
const browser = await puppeteer.launch({
|
||||
headless: true,
|
||||
});
|
||||
const page = await browser.newPage();
|
||||
await page.goto(BASE_URL + id);
|
||||
await timeout(5000);
|
||||
await page.emulateMediaType('print');
|
||||
if (!auth) {
|
||||
throw new functions.https.HttpsError(
|
||||
'failed-precondition',
|
||||
'The function must be called while authenticated.',
|
||||
);
|
||||
}
|
||||
|
||||
const browser = await puppeteer.launch({
|
||||
headless: true,
|
||||
});
|
||||
const page = await browser.newPage();
|
||||
await page.goto(BASE_URL + id);
|
||||
await timeout(5000);
|
||||
await page.emulateMediaType('print');
|
||||
let pdf;
|
||||
|
||||
if (type === 'single') {
|
||||
const height = await page.evaluate(() => {
|
||||
const { body } = document;
|
||||
const html = document.documentElement;
|
||||
@ -44,45 +53,19 @@ exports.printSinglePageResume = functions.https.onCall(
|
||||
|
||||
return maxHeight;
|
||||
});
|
||||
const pdf = await page.pdf({
|
||||
pdf = await page.pdf({
|
||||
printBackground: true,
|
||||
width: `21cm`,
|
||||
height: `${height}px`,
|
||||
pageRanges: '1',
|
||||
});
|
||||
await browser.close();
|
||||
return Buffer.from(pdf).toString('base64');
|
||||
},
|
||||
);
|
||||
|
||||
exports.printMultiPageResume = functions.https.onCall(
|
||||
async ({ id }, { auth }) => {
|
||||
if (!id) {
|
||||
throw new functions.https.HttpsError(
|
||||
'invalid-argument',
|
||||
'The function must be called with one arguments "id" containing the resume ID.',
|
||||
);
|
||||
}
|
||||
|
||||
if (!auth) {
|
||||
throw new functions.https.HttpsError(
|
||||
'failed-precondition',
|
||||
'The function must be called while authenticated.',
|
||||
);
|
||||
}
|
||||
|
||||
const browser = await puppeteer.launch({
|
||||
headless: true,
|
||||
});
|
||||
const page = await browser.newPage();
|
||||
await page.goto(BASE_URL + id);
|
||||
await timeout(5000);
|
||||
await page.emulateMediaType('print');
|
||||
const pdf = await page.pdf({
|
||||
} else if (type === 'multi') {
|
||||
pdf = await page.pdf({
|
||||
format: 'A4',
|
||||
printBackground: true,
|
||||
});
|
||||
await browser.close();
|
||||
return Buffer.from(pdf).toString('base64');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
await browser.close();
|
||||
return Buffer.from(pdf).toString('base64');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user