chore: disable puppeteer
This commit is contained in:
+11
-11
@@ -14,19 +14,19 @@ WORKDIR /app
|
|||||||
#
|
#
|
||||||
# This is a little brittle, since the puppeteer chrome could in theory diverge
|
# This is a little brittle, since the puppeteer chrome could in theory diverge
|
||||||
# from the official apt chrome's shared lib deps. But it works..
|
# from the official apt chrome's shared lib deps. But it works..
|
||||||
RUN apt-get update \
|
# RUN apt-get update \
|
||||||
&& apt-get install curl gnupg -y \
|
# && apt-get install curl gnupg -y \
|
||||||
&& curl --location --silent https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
|
# && curl --location --silent https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
|
||||||
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
|
# && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
|
||||||
&& apt-get update \
|
# && apt-get update \
|
||||||
&& apt-get install google-chrome-stable -y --no-install-recommends \
|
# && apt-get install google-chrome-stable -y --no-install-recommends \
|
||||||
&& apt-get remove google-chrome-stable -y \
|
# && apt-get remove google-chrome-stable -y \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
# && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Add emoji fonts.
|
# Add emoji fonts.
|
||||||
# Source: https://gist.github.com/win0err/9d8c7f0feabdfe8a4c9787b02c79ac51
|
# Source: https://gist.github.com/win0err/9d8c7f0feabdfe8a4c9787b02c79ac51
|
||||||
RUN mkdir ~/.fonts/ && \
|
# RUN mkdir ~/.fonts/ && \
|
||||||
wget https://github.com/samuelngs/apple-emoji-linux/releases/download/ios-15.4/AppleColorEmoji.ttf -O ~/.fonts/AppleColorEmoji.ttf
|
# wget https://github.com/samuelngs/apple-emoji-linux/releases/download/ios-15.4/AppleColorEmoji.ttf -O ~/.fonts/AppleColorEmoji.ttf
|
||||||
|
|
||||||
COPY package.json /app/
|
COPY package.json /app/
|
||||||
RUN npm install --frozen-lockfile
|
RUN npm install --frozen-lockfile
|
||||||
@@ -34,4 +34,4 @@ COPY ./ /app/
|
|||||||
|
|
||||||
ENV PORT 3002
|
ENV PORT 3002
|
||||||
EXPOSE 3002
|
EXPOSE 3002
|
||||||
CMD ["node", "server.js"]
|
CMD ["npm", "start"]
|
||||||
Generated
-1184
File diff suppressed because it is too large
Load Diff
@@ -36,7 +36,6 @@
|
|||||||
"multer": "^1.4.3",
|
"multer": "^1.4.3",
|
||||||
"nodemailer": "^6.9.5",
|
"nodemailer": "^6.9.5",
|
||||||
"nodemon": "^3.0.1",
|
"nodemon": "^3.0.1",
|
||||||
"puppeteer": "^20.9.0",
|
|
||||||
"zeptomail": "^6.0.0",
|
"zeptomail": "^6.0.0",
|
||||||
"zod": "^3.21.4"
|
"zod": "^3.21.4"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// const { getPdfBuffer } = require('./puppeteer');
|
// const { getPdfBuffer } = require('./puppeteer');
|
||||||
const { marked } = require('marked');
|
const { marked } = require('marked');
|
||||||
const puppeteer = require('puppeteer');
|
// const puppeteer = require('puppeteer');
|
||||||
|
|
||||||
function getHtmlTemplate(body) {
|
function getHtmlTemplate(body) {
|
||||||
return `
|
return `
|
||||||
@@ -155,57 +155,58 @@ function getCourseBody({ courseTitle, orgName, orgTheme, lessons }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function generateSinglePdfFromHtml(htmlContent, courseTitle, orgTheme) {
|
async function generateSinglePdfFromHtml(htmlContent, courseTitle, orgTheme) {
|
||||||
const args = [
|
throw 'Download disabled';
|
||||||
'--disable-web-security',
|
// const args = [
|
||||||
'--no-sandbox',
|
// '--disable-web-security',
|
||||||
'--disable-setuid-sandbox',
|
// '--no-sandbox',
|
||||||
];
|
// '--disable-setuid-sandbox',
|
||||||
const browser = await puppeteer.launch({
|
// ];
|
||||||
headless: 'new',
|
// const browser = await puppeteer.launch({
|
||||||
args,
|
// headless: 'new',
|
||||||
});
|
// args,
|
||||||
const page = await browser.newPage();
|
// });
|
||||||
|
// const page = await browser.newPage();
|
||||||
|
|
||||||
await page.setContent(htmlContent);
|
// await page.setContent(htmlContent);
|
||||||
|
|
||||||
const pdfOptions = {
|
// const pdfOptions = {
|
||||||
format: 'A4',
|
// format: 'A4',
|
||||||
printBackground: true,
|
// printBackground: true,
|
||||||
displayHeaderFooter: true,
|
// displayHeaderFooter: true,
|
||||||
headerTemplate:
|
// headerTemplate:
|
||||||
"<div><div class='pageNumber'></div> <div>/</div><div class='totalPages'></div></div>",
|
// "<div><div class='pageNumber'></div> <div>/</div><div class='totalPages'></div></div>",
|
||||||
footerTemplate: `
|
// footerTemplate: `
|
||||||
<div class="footer" style="position: relative; display: flex; text-align: right; margin-right: 5%; font-size: 8px; width: 297mm; padding-top: 30px;">
|
// <div class="footer" style="position: relative; display: flex; text-align: right; margin-right: 5%; font-size: 8px; width: 297mm; padding-top: 30px;">
|
||||||
<div style="position: absolute; right: 50%; bottom: 3%;"><span class="pageNumber"></span>/<span class="totalPages"></span></div>
|
// <div style="position: absolute; right: 50%; bottom: 3%;"><span class="pageNumber"></span>/<span class="totalPages"></span></div>
|
||||||
<div style="position: absolute; right: 0; bottom: 3%;">${courseTitle} | Powered by <a href="https://app.classroomio.com" style="text-decoration: underline;">ClassroomIO</a></div>
|
// <div style="position: absolute; right: 0; bottom: 3%;">${courseTitle} | Powered by <a href="https://app.classroomio.com" style="text-decoration: underline;">ClassroomIO</a></div>
|
||||||
</div>
|
// </div>
|
||||||
`,
|
// `,
|
||||||
margin: {
|
// margin: {
|
||||||
top: '0.3cm',
|
// top: '0.3cm',
|
||||||
bottom: '0.5cm',
|
// bottom: '0.5cm',
|
||||||
},
|
// },
|
||||||
};
|
// };
|
||||||
|
|
||||||
const numPages = await page.evaluate(() => {
|
// const numPages = await page.evaluate(() => {
|
||||||
const content = document.body; // Change this to the specific element containing content
|
// const content = document.body; // Change this to the specific element containing content
|
||||||
const style = window.getComputedStyle(content);
|
// const style = window.getComputedStyle(content);
|
||||||
const contentHeight = parseInt(style.height, 10);
|
// const contentHeight = parseInt(style.height, 10);
|
||||||
const pageHeight = 900; // Set this to an appropriate value based on your PDF format
|
// const pageHeight = 900; // Set this to an appropriate value based on your PDF format
|
||||||
|
|
||||||
return Math.ceil(contentHeight / pageHeight);
|
// return Math.ceil(contentHeight / pageHeight);
|
||||||
});
|
// });
|
||||||
|
|
||||||
const pagesPdfBuffer = [];
|
// const pagesPdfBuffer = [];
|
||||||
|
|
||||||
for (let currentPage = 1; currentPage <= numPages; currentPage++) {
|
// for (let currentPage = 1; currentPage <= numPages; currentPage++) {
|
||||||
await page.evaluate(() => {});
|
// await page.evaluate(() => {});
|
||||||
|
|
||||||
const pdfBuffer = await page.pdf(pdfOptions);
|
// const pdfBuffer = await page.pdf(pdfOptions);
|
||||||
pagesPdfBuffer.push(pdfBuffer);
|
// pagesPdfBuffer.push(pdfBuffer);
|
||||||
}
|
// }
|
||||||
|
|
||||||
await browser.close();
|
// await browser.close();
|
||||||
return Buffer.concat(pagesPdfBuffer);
|
// return Buffer.concat(pagesPdfBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function generateCoursePdf(params) {
|
async function generateCoursePdf(params) {
|
||||||
@@ -217,5 +218,5 @@ async function generateCoursePdf(params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
generateCoursePdf,
|
generateCoursePdf
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// const { getPdfBuffer } = require('./puppeteer');
|
// const { getPdfBuffer } = require('./puppeteer');
|
||||||
const { marked } = require('marked');
|
const { marked } = require('marked');
|
||||||
const puppeteer = require('puppeteer');
|
// const puppeteer = require('puppeteer');
|
||||||
|
|
||||||
function getHtmlTemplate(body) {
|
function getHtmlTemplate(body) {
|
||||||
return `
|
return `
|
||||||
@@ -75,15 +75,7 @@ function getHtmlTemplate(body) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLessonBody({
|
function getLessonBody({ title, number, orgName, note, slideUrl, video, courseTitle }) {
|
||||||
title,
|
|
||||||
number,
|
|
||||||
orgName,
|
|
||||||
note,
|
|
||||||
slideUrl,
|
|
||||||
video,
|
|
||||||
courseTitle,
|
|
||||||
}) {
|
|
||||||
const noteHtml = marked.parse(note);
|
const noteHtml = marked.parse(note);
|
||||||
const showExtraResources = slideUrl || (video && video.length > 0);
|
const showExtraResources = slideUrl || (video && video.length > 0);
|
||||||
return `
|
return `
|
||||||
@@ -148,54 +140,56 @@ function getLessonBody({
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function generateSinglePdfFromHtml(htmlContent, courseTitle) {
|
async function generateSinglePdfFromHtml(htmlContent, courseTitle) {
|
||||||
const args = [
|
// const args = [
|
||||||
'--disable-web-security',
|
// '--disable-web-security',
|
||||||
'--no-sandbox',
|
// '--no-sandbox',
|
||||||
'--disable-setuid-sandbox',
|
// '--disable-setuid-sandbox',
|
||||||
];
|
// ];
|
||||||
const browser = await puppeteer.launch({
|
// const browser = await puppeteer.launch({
|
||||||
headless: 'new',
|
// headless: 'new',
|
||||||
args,
|
// args,
|
||||||
});
|
// });
|
||||||
const page = await browser.newPage();
|
// const page = await browser.newPage();
|
||||||
|
|
||||||
await page.setContent(htmlContent);
|
// await page.setContent(htmlContent);
|
||||||
|
|
||||||
const pdfOptions = {
|
// const pdfOptions = {
|
||||||
format: 'A4',
|
// format: 'A4',
|
||||||
printBackground: true,
|
// printBackground: true,
|
||||||
displayHeaderFooter: true,
|
// displayHeaderFooter: true,
|
||||||
headerTemplate:
|
// headerTemplate:
|
||||||
"<div><div class='pageNumber'></div> <div>/</div><div class='totalPages'></div></div>",
|
// "<div><div class='pageNumber'></div> <div>/</div><div class='totalPages'></div></div>",
|
||||||
footerTemplate: `<div class="footer" style="text-align: right; margin-right: 5%; font-size: 8px; width: 297mm; padding-top: 30px;">
|
// footerTemplate: `<div class="footer" style="text-align: right; margin-right: 5%; font-size: 8px; width: 297mm; padding-top: 30px;">
|
||||||
${courseTitle} | Powered by <a href="https://app.classroomio.com" style="color: blue; text-decoration: underline;">ClassroomIO</a>
|
// ${courseTitle} | Powered by <a href="https://app.classroomio.com" style="color: blue; text-decoration: underline;">ClassroomIO</a>
|
||||||
</div>`,
|
// </div>`,
|
||||||
margin: {
|
// margin: {
|
||||||
top: '0.4cm',
|
// top: '0.4cm',
|
||||||
bottom: '1cm',
|
// bottom: '1cm',
|
||||||
},
|
// },
|
||||||
};
|
// };
|
||||||
|
|
||||||
const numPages = await page.evaluate(() => {
|
// const numPages = await page.evaluate(() => {
|
||||||
const content = document.body; // Change this to the specific element containing content
|
// const content = document.body; // Change this to the specific element containing content
|
||||||
const style = window.getComputedStyle(content);
|
// const style = window.getComputedStyle(content);
|
||||||
const contentHeight = parseInt(style.height, 10);
|
// const contentHeight = parseInt(style.height, 10);
|
||||||
const pageHeight = 900; // Set this to an appropriate value based on your PDF format
|
// const pageHeight = 900; // Set this to an appropriate value based on your PDF format
|
||||||
|
|
||||||
return Math.ceil(contentHeight / pageHeight);
|
// return Math.ceil(contentHeight / pageHeight);
|
||||||
});
|
// });
|
||||||
|
|
||||||
const pagesPdfBuffer = [];
|
// const pagesPdfBuffer = [];
|
||||||
|
|
||||||
for (let currentPage = 1; currentPage <= numPages; currentPage++) {
|
// for (let currentPage = 1; currentPage <= numPages; currentPage++) {
|
||||||
await page.evaluate(() => {});
|
// await page.evaluate(() => {});
|
||||||
|
|
||||||
const pdfBuffer = await page.pdf(pdfOptions);
|
// const pdfBuffer = await page.pdf(pdfOptions);
|
||||||
pagesPdfBuffer.push(pdfBuffer);
|
// pagesPdfBuffer.push(pdfBuffer);
|
||||||
}
|
// }
|
||||||
|
|
||||||
await browser.close();
|
// await browser.close();
|
||||||
return Buffer.concat(pagesPdfBuffer);
|
// return Buffer.concat(pagesPdfBuffer);
|
||||||
|
|
||||||
|
throw 'Download disabled';
|
||||||
}
|
}
|
||||||
|
|
||||||
async function generateLessonPdf(params) {
|
async function generateLessonPdf(params) {
|
||||||
@@ -223,5 +217,5 @@ async function generateLessonPdf(params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
generateLessonPdf,
|
generateLessonPdf
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,38 +1,39 @@
|
|||||||
const puppeteer = require('puppeteer');
|
// const puppeteer = require('puppeteer');
|
||||||
|
|
||||||
const getPdfBuffer = async (html, pdfParams) => {
|
const getPdfBuffer = async (html, pdfParams) => {
|
||||||
const args = [
|
throw 'Puppeteer disabled';
|
||||||
'--disable-web-security',
|
// const args = [
|
||||||
'--no-sandbox',
|
// '--disable-web-security',
|
||||||
'--disable-setuid-sandbox',
|
// '--no-sandbox',
|
||||||
];
|
// '--disable-setuid-sandbox',
|
||||||
const defaultPdfParams = {
|
// ];
|
||||||
width: '1123px',
|
// const defaultPdfParams = {
|
||||||
height: '794px',
|
// width: '1123px',
|
||||||
};
|
// height: '794px',
|
||||||
|
// };
|
||||||
|
|
||||||
// launch a new chrome instance
|
// // launch a new chrome instance
|
||||||
const browser = await puppeteer.launch({
|
// const browser = await puppeteer.launch({
|
||||||
headless: 'new',
|
// headless: 'new',
|
||||||
args,
|
// args,
|
||||||
});
|
// });
|
||||||
|
|
||||||
// create a new page
|
// // create a new page
|
||||||
const page = await browser.newPage();
|
// const page = await browser.newPage();
|
||||||
await page.setViewport({ width: 1123, height: 794 });
|
// await page.setViewport({ width: 1123, height: 794 });
|
||||||
await page.goto('data:text/html,' + html, { waitUntil: 'networkidle2' });
|
// await page.goto('data:text/html,' + html, { waitUntil: 'networkidle2' });
|
||||||
await page.addStyleTag({ content: '@page { size: auto; }' });
|
// await page.addStyleTag({ content: '@page { size: auto; }' });
|
||||||
await page.emulateMediaType('screen');
|
// await page.emulateMediaType('screen');
|
||||||
|
|
||||||
// create a pdf buffer
|
// // create a pdf buffer
|
||||||
const pdfBuffer = await page.pdf(pdfParams || defaultPdfParams);
|
// const pdfBuffer = await page.pdf(pdfParams || defaultPdfParams);
|
||||||
|
|
||||||
// close the browser
|
// // close the browser
|
||||||
await browser.close();
|
// await browser.close();
|
||||||
|
|
||||||
return pdfBuffer;
|
// return pdfBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getPdfBuffer,
|
getPdfBuffer
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,15 +9,16 @@ COPY ./pnpm-lock.yaml ./
|
|||||||
|
|
||||||
# Set environment variables
|
# Set environment variables
|
||||||
ENV IS_SELFHOSTED=true
|
ENV IS_SELFHOSTED=true
|
||||||
ENV PUBLIC_SUPABASE_URL=${PUBLIC_SUPABASE_URL}
|
ENV PUBLIC_SUPABASE_URL=$PUBLIC_SUPABASE_URL
|
||||||
ENV PUBLIC_SUPABASE_ANON_KEY=${PUBLIC_SUPABASE_ANON_KEY}
|
ENV PUBLIC_SUPABASE_ANON_KEY=$PUBLIC_SUPABASE_ANON_KEY
|
||||||
ENV PRIVATE_SUPABASE_SERVICE_ROLE=${PRIVATE_SUPABASE_SERVICE_ROLE}
|
ENV PRIVATE_SUPABASE_SERVICE_ROLE=$PRIVATE_SUPABASE_SERVICE_ROLE
|
||||||
ENV PRIVATE_APP_HOST=${PRIVATE_APP_HOST}
|
ENV PRIVATE_APP_HOST=$PRIVATE_APP_HOST
|
||||||
ENV PRIVATE_APP_SUBDOMAINS=${PRIVATE_APP_SUBDOMAINS}
|
ENV PRIVATE_APP_SUBDOMAINS=$PRIVATE_APP_SUBDOMAINS
|
||||||
ENV UNSPLASH_API_KEY=${UNSPLASH_API_KEY}
|
ENV UNSPLASH_API_KEY=$UNSPLASH_API_KEY
|
||||||
ENV OPENAI_API_KEY=${OPENAI_API_KEY}
|
ENV OPENAI_API_KEY=$OPENAI_API_KEY
|
||||||
ENV PUBLIC_SERVER_URL=${PUBLIC_SERVER_URL}
|
ENV PUBLIC_SERVER_URL=$PUBLIC_SERVER_URL
|
||||||
ENV PUBLIC_IP_REGISTRY_KEY=${PUBLIC_IP_REGISTRY_KEY}
|
ENV PUBLIC_IP_REGISTRY_KEY=$PUBLIC_IP_REGISTRY_KEY
|
||||||
|
ENV NODE_OPTIONS="--max-old-space-size=2048"
|
||||||
|
|
||||||
RUN pnpm i --frozen-lockfile
|
RUN pnpm i --frozen-lockfile
|
||||||
|
|
||||||
|
|||||||
@@ -12,13 +12,17 @@ export let supabase: SupabaseClient;
|
|||||||
export const getServerSupabase = () => {
|
export const getServerSupabase = () => {
|
||||||
if (supabase) return supabase;
|
if (supabase) return supabase;
|
||||||
|
|
||||||
supabase = createClient(config.supabaseConfig.url, env.PRIVATE_SUPABASE_SERVICE_ROLE || '', {
|
supabase = createClient(
|
||||||
auth: {
|
config.supabaseConfig.url,
|
||||||
persistSession: false,
|
env.PRIVATE_SUPABASE_SERVICE_ROLE || 'some-key-here',
|
||||||
autoRefreshToken: false,
|
{
|
||||||
detectSessionInUrl: false
|
auth: {
|
||||||
|
persistSession: false,
|
||||||
|
autoRefreshToken: false,
|
||||||
|
detectSessionInUrl: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
return supabase;
|
return supabase;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ services:
|
|||||||
- .:/app
|
- .:/app
|
||||||
- /app/node_modules
|
- /app/node_modules
|
||||||
- /app/apps/dashboard/node_modules
|
- /app/apps/dashboard/node_modules
|
||||||
|
- /app/apps/dashboard/build
|
||||||
# command: sh -c "npm install -g pnpm && rm -rf node_modules && yes | pnpm install --frozen-lockfile && cd apps/dashboard && pnpm build && pnpm start"
|
# command: sh -c "npm install -g pnpm && rm -rf node_modules && yes | pnpm install --frozen-lockfile && cd apps/dashboard && pnpm build && pnpm start"
|
||||||
environment:
|
environment:
|
||||||
- IS_SELFHOSTED=true
|
- IS_SELFHOSTED=true
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"concurrently": "^8.2.2",
|
"concurrently": "^8.2.2",
|
||||||
"cypress": "^13.8.0",
|
|
||||||
"eslint": "^8.54.0",
|
"eslint": "^8.54.0",
|
||||||
"prettier": "^3.1.0",
|
"prettier": "^3.1.0",
|
||||||
"prettier-plugin-svelte": "^3.1.2",
|
"prettier-plugin-svelte": "^3.1.2",
|
||||||
|
|||||||
Generated
+42
-1006
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user