Skip to content

Commit

Permalink
~
Browse files Browse the repository at this point in the history
  • Loading branch information
mdozairq committed Apr 2, 2024
1 parent ceb3858 commit e91f4b6
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 326 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.cache
2 changes: 1 addition & 1 deletion .puppeteerrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ const {join} = require('path');
*/
module.exports = {
// Changes the cache location for Puppeteer.
cacheDirectory: join("/root", '.cache', 'puppeteer'),
cacheDirectory: join(__dirname, '.cache', 'puppeteer'),
};
35 changes: 14 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
# Base Image: Use a lean Alpine base for smaller image size
FROM node:lts-alpine
FROM node:lts-alpine

# Environment Variable: Prevent Chromium download for faster builds
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
WORKDIR /app

# Install dependencies
WORKDIR /usr/src/app
RUN apk add --no-cache \
chromium \
nss \
ca-certificates
# Bundle your Node.js application
COPY package*.json ./
RUN npm install
# Google Chrome

# Copy your application code
COPY . .
# RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
# && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
# && apt-get update -qqy \
# && apt-get -qqy install google-chrome-stable \
# && rm /etc/apt/sources.list.d/google-chrome.list \
# && rm -rf /var/lib/apt/lists/* /var/cache/apt/* \
# && sed -i 's/"$HERE\/chrome"/xvfb-run "$HERE\/chrome" --no-sandbox/g' /opt/google/chrome/google-chrome

# Optimize for production (optional)
# If you have a production build step
# RUN npm run build
COPY . /app

# Expose a port (adjust if you use a different port in your app)
RUN npm install
RUN npx puppeteer browsers install chrome
EXPOSE 3000

# Command to run your application when the container starts
CMD [ "npm", "start" ]
CMD ["npm", "start"]
3 changes: 0 additions & 3 deletions README.md

This file was deleted.

33 changes: 27 additions & 6 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ app.get('/generate-mindfile', async (req, res) => {
}

const browser = await puppeteer.launch();
// const browser = await puppeteer.launch({
// headless: true,
// executablePath: '/usr/bin/chromium-browser',
// args: [
// '--no-sandbox',
// // '--disable-gpu',
// ]
// });

const page = await browser.newPage();

Expand All @@ -151,22 +159,34 @@ app.get('/generate-mindfile', async (req, res) => {
console.log("30%");

// Wait and click on first result
const startSelector = ".startButton_OY2G";
const startSelector = "button ::-p-text(Start)";
await page.waitForSelector(startSelector);
await page.click(startSelector);

console.log("50%");

while(true) {
const data = await page.evaluate(
() => document.querySelector(".padding-vert--md").outerHTML
);
try {
const startDownloadSelector = "div ::-p-text(Progress: )";
await page.waitForSelector(startDownloadSelector);
} catch {
break;
}
console.log(data);
}

const client = await page.createCDPSession();
await client.send("Page.setDownloadBehavior", {
behavior: "allow",
downloadPath: "./temp",
});

await delay(4000);
console.log("80%");

// // Locate the full title with a unique string
const startDownloadSelector = ".startButton_OY2G";
const startDownloadSelector = "button ::-p-text(Download compiled)";
await page.waitForSelector(startDownloadSelector);
await page.click(startDownloadSelector);

Expand All @@ -177,8 +197,9 @@ app.get('/generate-mindfile', async (req, res) => {

if (objectId) {
const bucketName = "zingcam";
const uploadPrefix = `flam/${env}/mindfile/`;
const uploadPrefix = `flam/${env}/mindfiles/`;
const mindFileUrl = await uploadToGCS(`./temp/${filename}`, bucketName, uploadPrefix, `${objectId}.mind`);
console.log(mindFileUrl);
let postbackPayload = {
"instant_id": objectId,
"mind_url": mindFileUrl
Expand Down Expand Up @@ -207,4 +228,4 @@ app.get('/generate-mindfile', async (req, res) => {
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, '0.0.0.0',() => console.log(`Server is running on Port: ${PORT}`))
app.listen(PORT, () => console.log(`Server is running on Port: ${PORT}`))
Loading

0 comments on commit e91f4b6

Please sign in to comment.